started timeslots package

This commit is contained in:
Radu Ioan Fericean
2012-01-30 19:04:37 +02:00
parent ff6817183d
commit 9f206bd22e
5 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package timeslots
import (
"log"
"github.com/fsouza/gokabinet/kc"
)
type KyotoStorage struct {
db *kc.DB
}
func NewKyotoStorage(filaName string) (*KyotoStorage, error) {
ndb, err := kc.Open(filaName, kc.READ)
log.Print("Starting kyoto storage")
return &KyotoStorage{db: ndb}, err
}
func (ks *KyotoStorage) Close() {
log.Print("Closing kyoto storage")
ks.db.Close()
}
func (ks *KyotoStorage) Get(key string) (value string, err error) {
return ks.db.Get(key)
}

View File

@@ -0,0 +1,28 @@
package timeslots
import (
"log"
"github.com/simonz05/godis"
)
type RedisStorage struct {
db *godis.Client
}
func NewRedisStorage(address string) (*RedisStorage, error) {
ndb:= godis.New(address, 10, "")
log.Print("Starting redis storage")
return &RedisStorage{db: ndb}, nil
}
func (rs *RedisStorage) Close() {
log.Print("Closing redis storage")
rs.db.Quit()
}
func (rs *RedisStorage) Get(key string) (string, error) {
elem, err := rs.db.Get(key)
return elem.String(), err
}

View File

@@ -0,0 +1,9 @@
package timeslots
/*
Interface for storage providers.
*/
type StorageGetter interface {
Close()
Get(key string) (string, error)
}

42
timeslots/timeslots.go Normal file
View File

@@ -0,0 +1,42 @@
package timeslots
import (
"time"
)
type BilingUnit int
type RatingProfile struct {
StartTime time.Time
ConnectFee float32
Price float32
BillingUnit BilingUnit
}
type ActivationPeriod struct {
ActivationTime time.Time
RatingProfiles []RatingProfile
}
type Customer struct {
Id string
Prefix string
ActivationPeriods []ActivationPeriod
}
const (
SECONDS =iota
COUNT
BYTES
)
type CallDescription struct {
tOR int
cstmId, subject, destination string
timeStart, timeEnd time.Time
}
func GetCost(in *CallDescription, sg StorageGetter) (result string, err error) {
return "", nil
}

View File

@@ -0,0 +1,11 @@
package timeslots
func TestSimple(*testing.T){
}
func BenchmarkSimple(b *testing.B) {
for i := 0; i < b.N; i++ {
GetCost()
}
}