mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
started timeslots package
This commit is contained in:
27
timeslots/kyoto_storage.go
Normal file
27
timeslots/kyoto_storage.go
Normal 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)
|
||||
}
|
||||
|
||||
28
timeslots/redis_storage.go
Normal file
28
timeslots/redis_storage.go
Normal 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
|
||||
}
|
||||
|
||||
9
timeslots/storage_interface.go
Normal file
9
timeslots/storage_interface.go
Normal 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
42
timeslots/timeslots.go
Normal 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
|
||||
}
|
||||
|
||||
11
timeslots/timeslots_test.go
Normal file
11
timeslots/timeslots_test.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package timeslots
|
||||
|
||||
func TestSimple(*testing.T){
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkSimple(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
GetCost()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user