From 7bc182e3745b137a4e137e5f77eb3c31cf1398da Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 13 Jan 2014 17:30:06 +0200 Subject: [PATCH] various go vet fixes --- engine/loader_csv_test.go | 1 + engine/loader_local_test.go | 7 ++++--- engine/storage_map.go | 31 +++++++++++-------------------- engine/storage_mongo.go | 11 ++++++----- engine/storage_redis.go | 17 +++++++++++------ engine/storage_sql.go | 14 ++++++++++++-- engine/timespans.go | 1 - 7 files changed, 45 insertions(+), 37 deletions(-) diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index bf26c1bc8..e54bc4876 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -142,6 +142,7 @@ func init() { csvr.LoadAccountActions() csvr.WriteToDatabase(false, false) dataStorage.CacheRating(nil, nil, nil) + accountingStorage.CacheAccounting(nil, nil) } func TestLoadDestinations(t *testing.T) { diff --git a/engine/loader_local_test.go b/engine/loader_local_test.go index fd446eaf8..afad41703 100644 --- a/engine/loader_local_test.go +++ b/engine/loader_local_test.go @@ -20,10 +20,11 @@ package engine import ( "flag" - "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/utils" "path" "testing" + + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/utils" ) /* @@ -289,7 +290,7 @@ func TestMatchLoadCsvWithStor(t *testing.T) { for idx, rs := range []*RedisStorage{rsCsv, rsStor, rsApier} { qVal, err := rs.db.Get(key) if err != nil { - t.Fatal("Could not retrieve key %s, error: %s", key, err.Error()) + t.Fatalf("Could not retrieve key %s, error: %s", key, err.Error()) } if idx == 0 { // Only compare at second iteration, first one is to set reference value refVal = qVal diff --git a/engine/storage_map.go b/engine/storage_map.go index 62a0288d5..5a3b59186 100644 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -46,10 +46,15 @@ func (ms *MapStorage) Flush() error { } func (ms *MapStorage) CacheRating(dKeys, rpKeys, rpfKeys []string) error { - if dKeys == nil && rpKeys == nil && rpfKeys == nil { - cache2go.Flush() + if dKeys == nil { + cache2go.RemPrefixKey(DESTINATION_PREFIX) + } + if rpKeys == nil { + cache2go.RemPrefixKey(RATING_PLAN_PREFIX) + } + if rpfKeys == nil { + cache2go.RemPrefixKey(RATING_PROFILE_PREFIX) } - cache2go.RemPrefixKey(DESTINATION_PREFIX) for k, _ := range ms.dict { if strings.HasPrefix(k, DESTINATION_PREFIX) { if _, err := ms.GetDestination(k[len(DESTINATION_PREFIX):]); err != nil { @@ -134,7 +139,7 @@ func (ms *MapStorage) SetRatingPlan(rp *RatingPlan) (err error) { result, err := ms.ms.Marshal(rp) ms.dict[RATING_PLAN_PREFIX+rp.Id] = result response := 0 - go historyScribe.Record(&history.Record{RATING_PLAN_PREFIX + rp.Id, rp}, &response) + go historyScribe.Record(&history.Record{Key: RATING_PLAN_PREFIX + rp.Id, Object: rp}, &response) cache2go.Cache(RATING_PLAN_PREFIX+rp.Id, rp) return } @@ -162,7 +167,7 @@ func (ms *MapStorage) SetRatingProfile(rpf *RatingProfile) (err error) { result, err := ms.ms.Marshal(rpf) ms.dict[RATING_PROFILE_PREFIX+rpf.Id] = result response := 0 - go historyScribe.Record(&history.Record{RATING_PROFILE_PREFIX + rpf.Id, rpf}, &response) + go historyScribe.Record(&history.Record{Key: RATING_PROFILE_PREFIX + rpf.Id, Object: rpf}, &response) cache2go.Cache(RATING_PROFILE_PREFIX+rpf.Id, rpf) return } @@ -191,19 +196,12 @@ func (ms *MapStorage) SetDestination(dest *Destination) (err error) { result, err := ms.ms.Marshal(dest) ms.dict[DESTINATION_PREFIX+dest.Id] = result response := 0 - go historyScribe.Record(&history.Record{DESTINATION_PREFIX + dest.Id, dest}, &response) + go historyScribe.Record(&history.Record{Key: DESTINATION_PREFIX + dest.Id, Object: dest}, &response) cache2go.Cache(DESTINATION_PREFIX+dest.Id, dest) return } func (ms *MapStorage) GetActions(key string, checkDb bool) (as Actions, err error) { - if values, ok := ms.dict[ACTION_PREFIX+key]; ok { - err = ms.ms.Unmarshal(values, &as) - } else { - return nil, errors.New("not found") - } - return - key = ACTION_PREFIX + key if x, err := cache2go.GetCached(key); err == nil { return x.(Actions), nil @@ -228,13 +226,6 @@ func (ms *MapStorage) SetActions(key string, as Actions) (err error) { } func (ms *MapStorage) GetSharedGroup(key string, checkDb bool) (sg *SharedGroup, err error) { - if values, ok := ms.dict[SHARED_GROUP_PREFIX+key]; ok { - err = ms.ms.Unmarshal(values, &sg) - } else { - return nil, errors.New("not found") - } - return - key = SHARED_GROUP_PREFIX + key if x, err := cache2go.GetCached(key); err == nil { return x.(*SharedGroup), nil diff --git a/engine/storage_mongo.go b/engine/storage_mongo.go index 4454a2aba..b54214383 100644 --- a/engine/storage_mongo.go +++ b/engine/storage_mongo.go @@ -20,11 +20,12 @@ package engine import ( "fmt" + "log" + "time" + "github.com/cgrates/cgrates/history" "labix.org/v2/mgo" "labix.org/v2/mgo/bson" - "log" - "time" ) type MongoStorage struct { @@ -137,7 +138,7 @@ func (ms *MongoStorage) GetRatingPlan(key string) (rp *RatingPlan, err error) { func (ms *MongoStorage) SetRatingPlan(rp *RatingPlan) error { if historyScribe != nil { response := 0 - historyScribe.Record(&history.Record{RATING_PLAN_PREFIX + rp.Id, rp}, &response) + historyScribe.Record(&history.Record{Key: RATING_PLAN_PREFIX + rp.Id, Object: rp}, &response) } return ms.db.C("ratingplans").Insert(rp) } @@ -151,7 +152,7 @@ func (ms *MongoStorage) GetRatingProfile(key string) (rp *RatingProfile, err err func (ms *MongoStorage) SetRatingProfile(rp *RatingProfile) error { if historyScribe != nil { response := 0 - historyScribe.Record(&history.Record{RATING_PROFILE_PREFIX + rp.Id, rp}, &response) + historyScribe.Record(&history.Record{Key: RATING_PROFILE_PREFIX + rp.Id, Object: rp}, &response) } return ms.db.C("ratingprofiles").Insert(rp) } @@ -168,7 +169,7 @@ func (ms *MongoStorage) GetDestination(key string) (result *Destination, err err func (ms *MongoStorage) SetDestination(dest *Destination) error { if historyScribe != nil { response := 0 - historyScribe.Record(&history.Record{DESTINATION_PREFIX + dest.Id, dest}, &response) + historyScribe.Record(&history.Record{Key: DESTINATION_PREFIX + dest.Id, Object: dest}, &response) } return ms.db.C("destinations").Insert(dest) } diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 513f7f0a9..fea4138ce 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -69,15 +69,20 @@ func (rs *RedisStorage) Flush() (err error) { } func (rs *RedisStorage) CacheRating(dKeys, rpKeys, rpfKeys []string) (err error) { - if dKeys == nil && rpKeys == nil && rpfKeys == nil { - cache2go.Flush() + if dKeys == nil { + cache2go.RemPrefixKey(DESTINATION_PREFIX) + } + if rpKeys == nil { + cache2go.RemPrefixKey(RATING_PLAN_PREFIX) + } + if rpfKeys == nil { + cache2go.RemPrefixKey(RATING_PROFILE_PREFIX) } if dKeys == nil { Logger.Info("Caching all destinations") if dKeys, err = rs.db.Keys(DESTINATION_PREFIX + "*"); err != nil { return } - cache2go.RemPrefixKey(DESTINATION_PREFIX) } else if len(rpKeys) != 0 { Logger.Info(fmt.Sprintf("Caching destinations: %v", dKeys)) } @@ -215,7 +220,7 @@ func (rs *RedisStorage) SetRatingPlan(rp *RatingPlan) (err error) { err = rs.db.Set(RATING_PLAN_PREFIX+rp.Id, b.Bytes()) if err == nil && historyScribe != nil { response := 0 - go historyScribe.Record(&history.Record{RATING_PLAN_PREFIX + rp.Id, rp}, &response) + go historyScribe.Record(&history.Record{Key: RATING_PLAN_PREFIX + rp.Id, Object: rp}, &response) } cache2go.Cache(RATING_PLAN_PREFIX+rp.Id, rp) return @@ -243,7 +248,7 @@ func (rs *RedisStorage) SetRatingProfile(rpf *RatingProfile) (err error) { err = rs.db.Set(RATING_PROFILE_PREFIX+rpf.Id, result) if err == nil && historyScribe != nil { response := 0 - go historyScribe.Record(&history.Record{RATING_PROFILE_PREFIX + rpf.Id, rpf}, &response) + go historyScribe.Record(&history.Record{Key: RATING_PROFILE_PREFIX + rpf.Id, Object: rpf}, &response) } cache2go.Cache(RATING_PROFILE_PREFIX+rpf.Id, rpf) return @@ -292,7 +297,7 @@ func (rs *RedisStorage) SetDestination(dest *Destination) (err error) { err = rs.db.Set(DESTINATION_PREFIX+dest.Id, b.Bytes()) if err == nil && historyScribe != nil { response := 0 - go historyScribe.Record(&history.Record{DESTINATION_PREFIX + dest.Id, dest}, &response) + go historyScribe.Record(&history.Record{Key: DESTINATION_PREFIX + dest.Id, Object: dest}, &response) } cache2go.Cache(DESTINATION_PREFIX+dest.Id, dest) return diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 539c41a29..4a688f5a9 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -443,7 +443,17 @@ func (self *SQLStorage) GetTPActions(tpid, actsId string) (*utils.TPActions, err if err = rows.Scan(&action, &balanceId, &dir, &units, &expTime, &destId, &rateSubject, &balanceWeight, &extraParameters, &weight); err != nil { return nil, err } - acts.Actions = append(acts.Actions, &utils.TPAction{action, balanceId, dir, units, expTime, destId, rateSubject, balanceWeight, extraParameters, weight}) + acts.Actions = append(acts.Actions, &utils.TPAction{ + Identifier: action, + BalanceType: balanceId, + Direction: dir, + Units: units, + ExpiryTime: expTime, + DestinationId: destId, + RatingSubject: rateSubject, + BalanceWeight: balanceWeight, + ExtraParameters: extraParameters, + Weight: weight}) } if i == 0 { return nil, nil @@ -516,7 +526,7 @@ func (self *SQLStorage) GetTPActionTimings(tpid, atId string) (map[string][]*uti if err = rows.Scan(&tag, &actionsId, &timingId, &weight); err != nil { return nil, err } - ats[tag] = append(ats[tag], &utils.TPActionTiming{actionsId, timingId, weight}) + ats[tag] = append(ats[tag], &utils.TPActionTiming{ActionsId: actionsId, TimingId: timingId, Weight: weight}) } return ats, nil } diff --git a/engine/timespans.go b/engine/timespans.go index 3ede27e85..3a6b462a0 100644 --- a/engine/timespans.go +++ b/engine/timespans.go @@ -216,7 +216,6 @@ func (ts *TimeSpan) getCost() float64 { } else { return ts.Increments[0].Cost * float64(len(ts.Increments)) } - return 0 } func (ts *TimeSpan) createIncrementsSlice() {