mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
various go vet fixes
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user