本文整理汇总了Golang中github.com/cgrates/cgrates/utils.NewStringMap函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStringMap函数的具体用法?Golang NewStringMap怎么用?Golang NewStringMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewStringMap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:perrault,项目名称:cgrates,代码行数:25,代码来源:storage_test.go
示例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
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:26,代码来源:storage_test.go
示例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)
}
}
开发者ID:cgrates,项目名称:cgrates,代码行数:54,代码来源:onstor_it_test.go
示例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)
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:51,代码来源:loader_csv_test.go
示例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)
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:50,代码来源:loader_csv_test.go
示例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)
}
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:7,代码来源:balances_test.go
示例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)
}
}
开发者ID:perrault,项目名称:cgrates,代码行数:47,代码来源:loader_csv_test.go
示例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")
}
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:8,代码来源:handler_derivedcharging_test.go
示例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")
}
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:8,代码来源:handler_derivedcharging_test.go
示例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)
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:43,代码来源:loader_csv_test.go
示例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)
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:10,代码来源:units_counter_test.go
示例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)
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:20,代码来源:balances_test.go
示例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)
}
}
开发者ID:perrault,项目名称:cgrates,代码行数:16,代码来源:derivedcharging_test.go
示例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
}
开发者ID:bhepp,项目名称:cgrates,代码行数:45,代码来源:derivedcharging.go
示例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)
}
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:23,代码来源:sharedgroup_test.go
示例16: TestBalanceMatchActionTriggerDestination
func TestBalanceMatchActionTriggerDestination(t *testing.T) {
at := &ActionTrigger{BalanceDestinationIds: utils.NewStringMap("test")}
b := &Balance{DestinationIds: utils.NewStringMap("test")}
if !b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
b.DestinationIds = utils.NewStringMap("test1")
if b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
b.DestinationIds = utils.NewStringMap("")
if b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
b.DestinationIds = utils.NewStringMap("test")
at.BalanceDestinationIds = utils.NewStringMap("")
if !b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:20,代码来源:balances_test.go
示例17: TestUnitsCounterAddBalanceExists
func TestUnitsCounterAddBalanceExists(t *testing.T) {
uc := &UnitCounter{
Counters: CounterFilters{&CounterFilter{Value: 1}, &CounterFilter{Value: 10, 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"))}}},
}
UnitCounters{utils.SMS: []*UnitCounter{uc}}.addUnits(5, utils.SMS, &CallCost{Destination: "0723"}, nil)
if len(uc.Counters) != 3 || uc.Counters[1].Value != 15 {
t.Error("Error adding minute bucket!")
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:9,代码来源:units_counter_test.go
示例18: SetActionTrigger
func (self *ApierV1) SetActionTrigger(attr AttrSetActionTrigger, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{"GroupID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
atrs, _ := self.RatingDb.GetActionTriggers(attr.GroupID, false, utils.NonTransactional)
var newAtr *engine.ActionTrigger
if attr.UniqueID != "" {
//search for exiting one
for _, atr := range atrs {
if atr.UniqueID == attr.UniqueID {
newAtr = atr
break
}
}
}
if newAtr == nil {
newAtr = &engine.ActionTrigger{}
atrs = append(atrs, newAtr)
}
newAtr.ID = attr.GroupID
if attr.UniqueID != "" {
newAtr.UniqueID = attr.UniqueID
} else {
newAtr.UniqueID = utils.GenUUID()
}
if attr.ThresholdType != nil {
newAtr.ThresholdType = *attr.ThresholdType
}
if attr.ThresholdValue != nil {
newAtr.ThresholdValue = *attr.ThresholdValue
}
if attr.Recurrent != nil {
newAtr.Recurrent = *attr.Recurrent
}
if attr.MinSleep != nil {
minSleep, err := utils.ParseDurationWithSecs(*attr.MinSleep)
if err != nil {
*reply = err.Error()
return err
}
newAtr.MinSleep = minSleep
}
if attr.ExpirationDate != nil {
expTime, err := utils.ParseTimeDetectLayout(*attr.ExpirationDate, self.Config.DefaultTimezone)
if err != nil {
*reply = err.Error()
return err
}
newAtr.ExpirationDate = expTime
}
if attr.ActivationDate != nil {
actTime, err := utils.ParseTimeDetectLayout(*attr.ActivationDate, self.Config.DefaultTimezone)
if err != nil {
*reply = err.Error()
return err
}
newAtr.ActivationDate = actTime
}
newAtr.Balance = &engine.BalanceFilter{}
if attr.BalanceID != nil {
newAtr.Balance.ID = attr.BalanceID
}
if attr.BalanceType != nil {
newAtr.Balance.Type = attr.BalanceType
}
if attr.BalanceDirections != nil {
newAtr.Balance.Directions = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceDirections...))
}
if attr.BalanceDestinationIds != nil {
newAtr.Balance.DestinationIDs = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceDestinationIds...))
}
if attr.BalanceWeight != nil {
newAtr.Balance.Weight = attr.BalanceWeight
}
if attr.BalanceExpirationDate != nil {
balanceExpTime, err := utils.ParseDate(*attr.BalanceExpirationDate)
if err != nil {
*reply = err.Error()
return err
}
newAtr.Balance.ExpirationDate = &balanceExpTime
}
if attr.BalanceTimingTags != nil {
newAtr.Balance.TimingIDs = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceTimingTags...))
}
if attr.BalanceRatingSubject != nil {
newAtr.Balance.RatingSubject = attr.BalanceRatingSubject
}
if attr.BalanceCategories != nil {
newAtr.Balance.Categories = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceCategories...))
}
if attr.BalanceSharedGroups != nil {
newAtr.Balance.SharedGroups = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceSharedGroups...))
}
if attr.BalanceBlocker != nil {
newAtr.Balance.Blocker = attr.BalanceBlocker
//.........这里部分代码省略.........
开发者ID:eloycoto,项目名称:cgrates,代码行数:101,代码来源:triggers.go
示例19: SetAccountActionTriggers
func (self *ApierV1) SetAccountActionTriggers(attr AttrSetAccountActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{"Tenant", "Account"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
accID := utils.AccountKey(attr.Tenant, attr.Account)
var account *engine.Account
_, err := engine.Guardian.Guard(func() (interface{}, error) {
if acc, err := self.AccountDb.GetAccount(accID); err == nil {
account = acc
} else {
return 0, err
}
for _, at := range account.ActionTriggers {
if (attr.UniqueID == "" || at.UniqueID == attr.UniqueID) &&
(attr.GroupID == "" || at.ID == attr.GroupID) {
// we have a winner
if attr.ThresholdType != nil {
at.ThresholdType = *attr.ThresholdType
}
if attr.ThresholdValue != nil {
at.ThresholdValue = *attr.ThresholdValue
}
if attr.Recurrent != nil {
at.Recurrent = *attr.Recurrent
}
if attr.Executed != nil {
at.Executed = *attr.Executed
}
if attr.MinSleep != nil {
minSleep, err := utils.ParseDurationWithSecs(*attr.MinSleep)
if err != nil {
return 0, err
}
at.MinSleep = minSleep
}
if attr.ExpirationDate != nil {
expTime, err := utils.ParseTimeDetectLayout(*attr.ExpirationDate, self.Config.DefaultTimezone)
if err != nil {
return 0, err
}
at.ExpirationDate = expTime
}
if attr.ActivationDate != nil {
actTime, err := utils.ParseTimeDetectLayout(*attr.ActivationDate, self.Config.DefaultTimezone)
if err != nil {
return 0, err
}
at.ActivationDate = actTime
}
at.Balance = &engine.BalanceFilter{}
if attr.BalanceID != nil {
at.Balance.ID = attr.BalanceID
}
if attr.BalanceType != nil {
at.Balance.Type = attr.BalanceType
}
if attr.BalanceDirections != nil {
at.Balance.Directions = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceDirections...))
}
if attr.BalanceDestinationIds != nil {
at.Balance.DestinationIDs = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceDestinationIds...))
}
if attr.BalanceWeight != nil {
at.Balance.Weight = attr.BalanceWeight
}
if attr.BalanceExpirationDate != nil {
balanceExpTime, err := utils.ParseDate(*attr.BalanceExpirationDate)
if err != nil {
return 0, err
}
at.Balance.ExpirationDate = &balanceExpTime
}
if attr.BalanceTimingTags != nil {
at.Balance.TimingIDs = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceTimingTags...))
}
if attr.BalanceRatingSubject != nil {
at.Balance.RatingSubject = attr.BalanceRatingSubject
}
if attr.BalanceCategories != nil {
at.Balance.Categories = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceCategories...))
}
if attr.BalanceSharedGroups != nil {
at.Balance.SharedGroups = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceSharedGroups...))
}
if attr.BalanceBlocker != nil {
at.Balance.Blocker = attr.BalanceBlocker
}
if attr.BalanceDisabled != nil {
at.Balance.Disabled = attr.BalanceDisabled
}
if attr.MinQueuedItems != nil {
at.MinQueuedItems = *attr.MinQueuedItems
}
if attr.ActionsID != nil {
at.ActionsID = *attr.ActionsID
}
}
}
//.........这里部分代码省略.........
开发者ID:eloycoto,项目名称:cgrates,代码行数:101,代码来源:triggers.go
示例20: TestUnitCountersCountAllMonetary
func TestUnitCountersCountAllMonetary(t *testing.T) {
a := &Account{
ActionTriggers: ActionTriggers{
&ActionTrigger{
UniqueID: "TestTR1",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.MONETARY),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT, utils.IN)),
Weight: utils.Float64Pointer(10),
},
},
&ActionTrigger{
UniqueID: "TestTR11",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.MONETARY),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT, utils.IN)),
Weight: utils.Float64Pointer(10),
},
},
&ActionTrigger{
UniqueID: "TestTR2",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.VOICE),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT, utils.IN)),
Weight: utils.Float64Pointer(10),
},
},
&ActionTrigger{
UniqueID: "TestTR3",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.VOICE),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT, utils.IN)),
Weight: utils.Float64Pointer(10),
},
},
&ActionTrigger{
UniqueID: "TestTR4",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.SMS),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT, utils.IN)),
Weight: utils.Float64Pointer(10),
},
},
&ActionTrigger{
UniqueID: "TestTR5",
ThresholdType: utils.TRIGGER_MAX_BALANCE,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.SMS),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT, utils.IN)),
Weight: utils.Float64Pointer(10),
},
},
},
}
a.InitCounters()
a.UnitCounters.addUnits(10, utils.MONETARY, &CallCost{}, nil)
if len(a.UnitCounters) != 3 ||
len(a.UnitCounters[utils.MONETARY][0].Counters) != 2 ||
a.UnitCounters[utils.MONETARY][0].Counters[0].Value != 10 ||
a.UnitCounters[utils.MONETARY][0].Counters[1].Value != 10 {
for key, counters := range a.UnitCounters {
t.Log(key)
for _, uc := range counters {
t.Logf("UC: %+v", uc)
for _, b := range uc.Counters {
t.Logf("B: %+v", b)
}
}
}
t.Errorf("Error Initializing adding unit counters: %v", len(a.UnitCounters))
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:78,代码来源:units_counter_test.go
注:本文中的github.com/cgrates/cgrates/utils.NewStringMap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论