本文整理匯總了Golang中github.com/cgrates/cgrates/utils.NewStringMap函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewStringMap函數的具體用法?Golang NewStringMap怎麽用?Golang NewStringMap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewStringMap函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetUB
func GetUB() *Account {
uc := &UnitCounter{
BalanceType: utils.SMS,
Balances: BalanceChain{&Balance{Value: 1}, &Balance{Weight: 20, DestinationIds: utils.NewStringMap("NAT")}, &Balance{Weight: 10, DestinationIds: utils.NewStringMap("RET")}},
}
at := &ActionTrigger{
Id: "some_uuid",
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT),
ThresholdValue: 100.0,
BalanceDestinationIds: utils.NewStringMap("NAT"),
Weight: 10.0,
ActionsId: "Commando",
}
var zeroTime time.Time
zeroTime = zeroTime.UTC() // for deep equal to find location
ub := &Account{
Id: "rif",
AllowNegative: true,
BalanceMap: map[string]BalanceChain{utils.SMS: BalanceChain{&Balance{Value: 14, ExpirationDate: zeroTime}}, utils.DATA: BalanceChain{&Balance{Value: 1024, ExpirationDate: zeroTime}}, utils.VOICE: BalanceChain{&Balance{Weight: 20, DestinationIds: utils.NewStringMap("NAT")}, &Balance{Weight: 10, DestinationIds: utils.NewStringMap("RET")}}},
UnitCounters: UnitCounters{uc, uc},
ActionTriggers: ActionTriggers{at, at, at},
}
return ub
}
示例2: GetUB
func GetUB() *Account {
uc := &UnitCounter{
Counters: CounterFilters{&CounterFilter{Value: 1}, &CounterFilter{Filter: &BalanceFilter{Weight: utils.Float64Pointer(20), DestinationIDs: utils.StringMapPointer(utils.NewStringMap("NAT"))}}, &CounterFilter{Filter: &BalanceFilter{Weight: utils.Float64Pointer(10), DestinationIDs: utils.StringMapPointer(utils.NewStringMap("RET"))}}},
}
at := &ActionTrigger{
ID: "some_uuid",
ThresholdValue: 100.0,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.MONETARY),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT)),
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("NAT")),
},
Weight: 10.0,
ActionsID: "Commando",
}
var zeroTime time.Time
zeroTime = zeroTime.UTC() // for deep equal to find location
ub := &Account{
ID: "rif",
AllowNegative: true,
BalanceMap: map[string]Balances{utils.SMS: Balances{&Balance{Value: 14, ExpirationDate: zeroTime}}, utils.DATA: Balances{&Balance{Value: 1024, ExpirationDate: zeroTime}}, utils.VOICE: Balances{&Balance{Weight: 20, DestinationIDs: utils.NewStringMap("NAT")}, &Balance{Weight: 10, DestinationIDs: utils.NewStringMap("RET")}}},
UnitCounters: UnitCounters{utils.SMS: []*UnitCounter{uc, uc}},
ActionTriggers: ActionTriggers{at, at, at},
}
return ub
}
示例3: testOnStorITCacheActions
func testOnStorITCacheActions(t *testing.T) {
acts := Actions{
&Action{
Id: "MINI",
ActionType: TOPUP_RESET,
ExpirationString: UNLIMITED,
Weight: 10,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.MONETARY),
Uuid: utils.StringPointer(utils.GenUUID()),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT)),
Value: &utils.ValueFormula{Static: 10,
Params: make(map[string]interface{})},
Weight: utils.Float64Pointer(10),
Disabled: utils.BoolPointer(false),
Timings: make([]*RITiming, 0),
Blocker: utils.BoolPointer(false),
},
},
&Action{
Id: "MINI",
ActionType: TOPUP,
ExpirationString: UNLIMITED,
Weight: 10,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.VOICE),
Uuid: utils.StringPointer(utils.GenUUID()),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT)),
Value: &utils.ValueFormula{Static: 100,
Params: make(map[string]interface{})},
Weight: utils.Float64Pointer(10),
RatingSubject: utils.StringPointer("test"),
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("NAT")),
Disabled: utils.BoolPointer(false),
Timings: make([]*RITiming, 0),
Blocker: utils.BoolPointer(false),
},
},
}
if err := onStor.SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil {
t.Error(err)
}
if _, hasIt := cache.Get(utils.ACTION_PREFIX + acts[0].Id); hasIt {
t.Error("Already in cache")
}
if err := onStor.CacheDataFromDB(utils.ACTION_PREFIX, []string{acts[0].Id}, false); err != nil {
t.Error(err)
}
if itm, hasIt := cache.Get(utils.ACTION_PREFIX + acts[0].Id); !hasIt {
t.Error("Did not cache")
} else if rcv := itm.(Actions); !reflect.DeepEqual(acts, rcv) {
t.Errorf("Expecting: %+v, received: %+v", acts, rcv)
}
}
示例4: TestLoadAccountActions
func TestLoadAccountActions(t *testing.T) {
if len(csvr.accountActions) != 17 {
t.Error("Failed to load account actions: ", len(csvr.accountActions))
}
aa := csvr.accountActions["vdf:minitsboy"]
expected := &Account{
ID: "vdf:minitsboy",
UnitCounters: UnitCounters{
utils.VOICE: []*UnitCounter{
&UnitCounter{
CounterType: "*event",
Counters: CounterFilters{
&CounterFilter{
Value: 0,
Filter: &BalanceFilter{
ID: utils.StringPointer("st0"),
Type: utils.StringPointer(utils.VOICE),
Directions: utils.StringMapPointer(utils.NewStringMap("*out")),
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("GERMANY_O2")),
SharedGroups: nil,
Categories: nil,
TimingIDs: nil,
},
},
},
},
},
},
ActionTriggers: csvr.actionsTriggers["STANDARD_TRIGGER"],
}
// set propper uuid
for i, atr := range aa.ActionTriggers {
csvr.actionsTriggers["STANDARD_TRIGGER"][i].ID = atr.ID
}
for i, b := range aa.UnitCounters[utils.VOICE][0].Counters {
expected.UnitCounters[utils.VOICE][0].Counters[i].Filter.ID = b.Filter.ID
}
if !reflect.DeepEqual(aa.UnitCounters[utils.VOICE][0].Counters[0], expected.UnitCounters[utils.VOICE][0].Counters[0]) {
t.Errorf("Error loading account action: %+v", utils.ToIJSON(aa.UnitCounters[utils.VOICE][0].Counters[0].Filter))
}
// test that it does not overwrite balances
existing, err := accountingStorage.GetAccount(aa.ID)
if err != nil || len(existing.BalanceMap) != 2 {
t.Errorf("The account was not set before load: %+v", existing)
}
accountingStorage.SetAccount(aa)
existing, err = accountingStorage.GetAccount(aa.ID)
if err != nil || len(existing.BalanceMap) != 2 {
t.Errorf("The set account altered the balances: %+v", existing)
}
}
示例5: TestLoadActionTriggers
func TestLoadActionTriggers(t *testing.T) {
if len(csvr.actionsTriggers) != 7 {
t.Error("Failed to load action triggers: ", len(csvr.actionsTriggers))
}
atr := csvr.actionsTriggers["STANDARD_TRIGGER"][0]
expected := &ActionTrigger{
ID: "STANDARD_TRIGGER",
UniqueID: "st0",
ThresholdType: utils.TRIGGER_MIN_EVENT_COUNTER,
ThresholdValue: 10,
Balance: &BalanceFilter{
ID: nil,
Type: utils.StringPointer(utils.VOICE),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT)),
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("GERMANY_O2")),
Categories: nil,
TimingIDs: nil,
SharedGroups: nil,
Disabled: nil,
Blocker: nil,
},
Weight: 10,
ActionsID: "SOME_1",
Executed: false,
}
if !reflect.DeepEqual(atr, expected) {
t.Errorf("Error loading action trigger: %+v", utils.ToIJSON(atr.Balance))
}
atr = csvr.actionsTriggers["STANDARD_TRIGGER"][1]
expected = &ActionTrigger{
ID: "STANDARD_TRIGGER",
UniqueID: "st1",
ThresholdType: utils.TRIGGER_MAX_BALANCE,
ThresholdValue: 200,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.VOICE),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT)),
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("GERMANY")),
Categories: nil,
TimingIDs: nil,
SharedGroups: nil,
},
Weight: 10,
ActionsID: "SOME_2",
Executed: false,
}
if !reflect.DeepEqual(atr, expected) {
t.Errorf("Error loading action trigger: %+v", atr)
}
}
示例6: TestBalanceClone
func TestBalanceClone(t *testing.T) {
mb1 := &Balance{Value: 1, Weight: 2, RatingSubject: "test", DestinationIds: utils.NewStringMap("5")}
mb2 := mb1.Clone()
if mb1 == mb2 || !mb1.Equal(mb2) {
t.Errorf("Cloning failure: \n%+v\n%+v", mb1, mb2)
}
}
示例7: TestLoadAccountActions
func TestLoadAccountActions(t *testing.T) {
if len(csvr.accountActions) != 11 {
t.Error("Failed to load account actions: ", len(csvr.accountActions))
}
aa := csvr.accountActions["vdf:minitsboy"]
expected := &Account{
Id: "vdf:minitsboy",
UnitCounters: UnitCounters{
&UnitCounter{
BalanceType: "*voice",
CounterType: "*event",
Balances: BalanceChain{
&Balance{
Id: "2c2ce3c9-d62b-49dc-82a5-2a17bdc6eb4e",
Value: 0,
Directions: utils.NewStringMap("*out"),
DestinationIds: utils.NewStringMap("GERMANY_O2"),
SharedGroups: utils.StringMap{},
Categories: utils.StringMap{},
TimingIDs: utils.StringMap{},
},
},
},
},
ActionTriggers: csvr.actionsTriggers["STANDARD_TRIGGER"],
}
// set propper uuid
for i, atr := range aa.ActionTriggers {
csvr.actionsTriggers["STANDARD_TRIGGER"][i].Id = atr.Id
}
for i, b := range aa.UnitCounters[0].Balances {
expected.UnitCounters[0].Balances[i].Id = b.Id
}
if !reflect.DeepEqual(aa.UnitCounters[0].Balances[0], expected.UnitCounters[0].Balances[0]) {
t.Errorf("Error loading account action: %+v \n %+v", aa.UnitCounters[0].Balances[0], expected.UnitCounters[0].Balances[0])
}
// test that it does not overwrite balances
existing, err := accountingStorage.GetAccount(aa.Id)
if err != nil || len(existing.BalanceMap) != 2 {
t.Errorf("The account was not set before load: %+v", existing)
}
accountingStorage.SetAccount(aa)
existing, err = accountingStorage.GetAccount(aa.Id)
if err != nil || len(existing.BalanceMap) != 2 {
t.Errorf("The set account altered the balances: %+v", existing)
}
}
示例8: TestHandleDeivedChargersMatchDestNegativeSpec
func TestHandleDeivedChargersMatchDestNegativeSpec(t *testing.T) {
dcs := &utils.DerivedChargers{
DestinationIDs: utils.NewStringMap("NAT", "!SPEC"),
}
if DerivedChargersMatchesDest(dcs, "0723045326") {
t.Error("Derived charger failed to match dest")
}
}
示例9: TestHandleDeivedChargersMatchDestRet
func TestHandleDeivedChargersMatchDestRet(t *testing.T) {
dcs := &utils.DerivedChargers{
DestinationIDs: utils.NewStringMap("RET"),
}
if !DerivedChargersMatchesDest(dcs, "0723045326") {
t.Error("Derived charger failed to match dest")
}
}
示例10: TestLoadActionTriggers
func TestLoadActionTriggers(t *testing.T) {
if len(csvr.actionsTriggers) != 7 {
t.Error("Failed to load action triggers: ", len(csvr.actionsTriggers))
}
atr := csvr.actionsTriggers["STANDARD_TRIGGER"][0]
expected := &ActionTrigger{
ID: "STANDARD_TRIGGER",
UniqueID: "st0",
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT),
ThresholdType: utils.TRIGGER_MIN_EVENT_COUNTER,
ThresholdValue: 10,
BalanceDestinationIds: utils.NewStringMap("GERMANY_O2"),
BalanceCategories: utils.StringMap{},
BalanceTimingTags: utils.StringMap{},
BalanceSharedGroups: utils.StringMap{},
Weight: 10,
ActionsId: "SOME_1",
Executed: false,
}
if !reflect.DeepEqual(atr, expected) {
t.Errorf("Error loading action trigger: %+v", atr)
}
atr = csvr.actionsTriggers["STANDARD_TRIGGER"][1]
expected = &ActionTrigger{
ID: "STANDARD_TRIGGER",
UniqueID: "st1",
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT),
ThresholdType: utils.TRIGGER_MAX_BALANCE,
ThresholdValue: 200,
BalanceDestinationIds: utils.NewStringMap("GERMANY"),
BalanceCategories: utils.StringMap{},
BalanceTimingTags: utils.StringMap{},
BalanceSharedGroups: utils.StringMap{},
Weight: 10,
ActionsId: "SOME_2",
Executed: false,
}
if !reflect.DeepEqual(atr, expected) {
t.Errorf("Error loading action trigger: %+v", atr)
}
}
示例11: TestUnitsCounterAddBalance
func TestUnitsCounterAddBalance(t *testing.T) {
uc := &UnitCounter{
BalanceType: utils.SMS,
Balances: BalanceChain{&Balance{Value: 1}, &Balance{Weight: 20, DestinationIds: utils.NewStringMap("NAT")}, &Balance{Weight: 10, DestinationIds: utils.NewStringMap("RET")}},
}
UnitCounters{uc}.addUnits(20, utils.SMS, &CallCost{Destination: "test"}, nil)
if len(uc.Balances) != 3 {
t.Error("Error adding minute bucket: ", uc.Balances)
}
}
示例12: TestBalanceMatchActionTriggerSharedGroup
func TestBalanceMatchActionTriggerSharedGroup(t *testing.T) {
at := &ActionTrigger{Balance: &BalanceFilter{SharedGroups: utils.StringMapPointer(utils.NewStringMap("test"))}}
b := &Balance{SharedGroups: utils.NewStringMap("test")}
if !b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
b.SharedGroups = utils.NewStringMap("test1")
if b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
b.SharedGroups = utils.NewStringMap("")
if b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
b.SharedGroups = utils.NewStringMap("test")
at.Balance.SharedGroups = nil
if !b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
}
示例13: TestGetDC
func TestGetDC(t *testing.T) {
attrs := utils.AttrDerivedChargers{Tenant: "cgrates.org", Category: "call", Direction: "*out", Account: "dan", Subject: "dan"}
eDcs := utils.DerivedChargers{DestinationIds: utils.NewStringMap(),
Chargers: []*utils.DerivedCharger{
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
AccountField: "rif", SubjectField: "rif", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", UsageField: "*default"},
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
AccountField: "ivo", SubjectField: "ivo", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", UsageField: "*default"},
}}
var dcs utils.DerivedChargers
if err := apierDcT.GetDerivedChargers(attrs, &dcs); err != nil {
t.Error("Unexpected error", err.Error())
} else if !reflect.DeepEqual(dcs, eDcs) {
t.Errorf("Expecting: %v, received: %v", eDcs.DestinationIds, dcs.DestinationIds)
}
}
示例14: SetDerivedChargers
func (self *ApierV1) SetDerivedChargers(attrs AttrSetDerivedChargers, reply *string) (err error) {
if len(attrs.DerivedChargers) == 0 {
return utils.NewErrMandatoryIeMissing("DerivedChargers")
}
if len(attrs.Direction) == 0 {
attrs.Direction = utils.OUT
}
if len(attrs.Tenant) == 0 {
attrs.Tenant = utils.ANY
}
if len(attrs.Category) == 0 {
attrs.Category = utils.ANY
}
if len(attrs.Account) == 0 {
attrs.Account = utils.ANY
}
if len(attrs.Subject) == 0 {
attrs.Subject = utils.ANY
}
for _, dc := range attrs.DerivedChargers {
if _, err = utils.ParseRSRFields(dc.RunFilters, utils.INFIELD_SEP); err != nil { // Make sure rules are OK before loading in db
return fmt.Errorf("%s:%s", utils.ErrParserError.Error(), err.Error())
}
}
dcKey := utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, attrs.Category, attrs.Account, attrs.Subject)
if !attrs.Overwrite {
if exists, err := self.RatingDb.HasData(utils.DERIVEDCHARGERS_PREFIX, dcKey); err != nil {
return utils.NewErrServerError(err)
} else if exists {
return utils.ErrExists
}
}
dstIds := strings.Split(attrs.DestinationIds, utils.INFIELD_SEP)
dcs := &utils.DerivedChargers{DestinationIDs: utils.NewStringMap(dstIds...), Chargers: attrs.DerivedChargers}
if err := self.RatingDb.SetDerivedChargers(dcKey, dcs); err != nil {
return utils.NewErrServerError(err)
}
if err := self.RatingDb.CacheRatingPrefixValues(map[string][]string{
utils.DERIVEDCHARGERS_PREFIX: []string{utils.DERIVEDCHARGERS_PREFIX + dcKey},
}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
示例15: TestSharedSetGet
func TestSharedSetGet(t *testing.T) {
id := "TEST_SG100"
sg := &SharedGroup{
Id: id,
AccountParameters: map[string]*SharingParameters{
"test": &SharingParameters{Strategy: STRATEGY_HIGHEST},
},
MemberIds: utils.NewStringMap("1", "2", "3"),
}
err := ratingStorage.SetSharedGroup(sg, utils.NonTransactional)
if err != nil {
t.Error("Error storing Shared groudp: ", err)
}
received, err := ratingStorage.GetSharedGroup(id, true, utils.NonTransactional)
if err != nil || received == nil || !reflect.DeepEqual(sg, received) {
t.Error("Error getting shared group: ", err, received)
}
received, err = ratingStorage.GetSharedGroup(id, false, utils.NonTransactional)
if err != nil || received == nil || !reflect.DeepEqual(sg, received) {
t.Error("Error getting cached shared group: ", err, received)
}
}