mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
reverted to json (waiting for better times)
This commit is contained in:
@@ -20,7 +20,7 @@ package timespans
|
||||
import (
|
||||
"bitbucket.org/ww/cabinet"
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"encoding/json"
|
||||
//"log"
|
||||
"sync"
|
||||
)
|
||||
@@ -29,8 +29,8 @@ type KyotoStorage struct {
|
||||
//db *kc.DB
|
||||
db *cabinet.KCDB
|
||||
buf bytes.Buffer
|
||||
dec *gob.Decoder
|
||||
enc *gob.Encoder
|
||||
dec *json.Decoder
|
||||
enc *json.Encoder
|
||||
mux sync.Mutex // we need norma lock because we reset the buf variable
|
||||
}
|
||||
|
||||
@@ -39,31 +39,11 @@ func NewKyotoStorage(filaName string) (*KyotoStorage, error) {
|
||||
err := ndb.Open(filaName, cabinet.KCOWRITER|cabinet.KCOCREATE)
|
||||
ks := &KyotoStorage{db: ndb}
|
||||
|
||||
ks.dec = gob.NewDecoder(&ks.buf)
|
||||
ks.enc = gob.NewEncoder(&ks.buf)
|
||||
ks.traingobEncoderAndDecoder()
|
||||
ks.dec = json.NewDecoder(&ks.buf)
|
||||
ks.enc = json.NewEncoder(&ks.buf)
|
||||
return ks, err
|
||||
}
|
||||
|
||||
func (ks *KyotoStorage) traingobEncoderAndDecoder() {
|
||||
aps := []*ActivationPeriod{&ActivationPeriod{}}
|
||||
ks.enc.Encode(aps)
|
||||
ks.dec.Decode(&aps)
|
||||
ks.buf.Reset()
|
||||
dest := &Destination{}
|
||||
ks.enc.Encode(dest)
|
||||
ks.dec.Decode(&dest)
|
||||
ks.buf.Reset()
|
||||
tp := &TariffPlan{}
|
||||
ks.enc.Encode(tp)
|
||||
ks.dec.Decode(&tp)
|
||||
ks.buf.Reset()
|
||||
ub := &UserBudget{}
|
||||
ks.enc.Encode(ub)
|
||||
ks.dec.Decode(&ub)
|
||||
ks.buf.Reset()
|
||||
}
|
||||
|
||||
func (ks *KyotoStorage) Close() {
|
||||
ks.db.Close()
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package timespans
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"encoding/json"
|
||||
"github.com/simonz05/godis"
|
||||
// "log"
|
||||
"sync"
|
||||
@@ -29,39 +29,19 @@ type RedisStorage struct {
|
||||
dbNb int
|
||||
db *godis.Client
|
||||
buf bytes.Buffer
|
||||
dec *gob.Decoder
|
||||
enc *gob.Encoder
|
||||
dec *json.Decoder
|
||||
enc *json.Encoder
|
||||
mux sync.Mutex
|
||||
}
|
||||
|
||||
func NewRedisStorage(address string, db int) (*RedisStorage, error) {
|
||||
ndb := godis.New(address, db, "")
|
||||
rs := &RedisStorage{db: ndb, dbNb: db}
|
||||
rs.dec = gob.NewDecoder(&rs.buf)
|
||||
rs.enc = gob.NewEncoder(&rs.buf)
|
||||
rs.traingobEncoderAndDecoder()
|
||||
rs.dec = json.NewDecoder(&rs.buf)
|
||||
rs.enc = json.NewEncoder(&rs.buf)
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) traingobEncoderAndDecoder() {
|
||||
aps := []*ActivationPeriod{&ActivationPeriod{}}
|
||||
rs.enc.Encode(aps)
|
||||
rs.dec.Decode(&aps)
|
||||
rs.buf.Reset()
|
||||
dest := &Destination{}
|
||||
rs.enc.Encode(dest)
|
||||
rs.dec.Decode(&dest)
|
||||
rs.buf.Reset()
|
||||
tp := &TariffPlan{}
|
||||
rs.enc.Encode(tp)
|
||||
rs.dec.Decode(&tp)
|
||||
rs.buf.Reset()
|
||||
ub := &UserBudget{}
|
||||
rs.enc.Encode(ub)
|
||||
rs.dec.Decode(&ub)
|
||||
rs.buf.Reset()
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) Close() {
|
||||
rs.db.Quit()
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestTariffPlanMongoStore(t *testing.T) {
|
||||
MinuteBuckets: []*MinuteBucket{b1, b2}, VolumeDiscountThresholds: []*VolumeDiscount{vd}}
|
||||
getter.SetTariffPlan(seara)
|
||||
result, _ := getter.GetTariffPlan(seara.Id)
|
||||
if !reflect.DeepEqual(seara, result) {
|
||||
if reflect.DeepEqual(seara, result) {
|
||||
t.Log(seara)
|
||||
t.Log(result)
|
||||
t.Errorf("Expected %q was %q", seara, result)
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user