本文整理匯總了Golang中github.com/cgrates/cgrates/utils.SplitPrefix函數的典型用法代碼示例。如果您正苦於以下問題:Golang SplitPrefix函數的具體用法?Golang SplitPrefix怎麽用?Golang SplitPrefix使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了SplitPrefix函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addUnits
// Adds the units from the received balance to an existing balance if the destination
// is the same or ads the balance to the list if none matches.
func (uc *UnitsCounter) addUnits(amount float64, prefix string) {
counted := false
if prefix != "" {
for _, mb := range uc.Balances {
if !mb.HasDestination() {
continue
}
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
if _, found := destIds[mb.DestinationIds]; found {
mb.AddValue(amount)
counted = true
break
}
}
if counted {
break
}
}
}
}
if !counted {
// use general balance
b := uc.GetGeneralBalance()
b.AddValue(amount)
}
}
示例2: GetLCREntryForPrefix
func (lcra *LCRActivation) GetLCREntryForPrefix(destination string) *LCREntry {
var potentials LCREntriesSorter
for _, p := range utils.SplitPrefix(destination, MIN_PREFIX_MATCH) {
if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[string]struct{})
for dId := range destIds {
for _, entry := range lcra.Entries {
if entry.DestinationId == dId {
entry.precision = len(p)
potentials = append(potentials, entry)
}
}
}
}
}
if len(potentials) > 0 {
// sort by precision and weight
potentials.Sort()
return potentials[0]
}
// return the *any entry if it exists
for _, entry := range lcra.Entries {
if entry.DestinationId == utils.ANY {
return entry
}
}
return nil
}
示例3: MatchCCFilter
func (cc *CallCost) MatchCCFilter(bf *BalanceFilter) bool {
if bf == nil {
return true
}
if bf.Categories != nil && cc.Category != "" && (*bf.Categories)[cc.Category] == false {
return false
}
if bf.Directions != nil && cc.Direction != "" && (*bf.Directions)[cc.Direction] == false {
return false
}
// match destination ids
foundMatchingDestID := false
if bf.DestinationIDs != nil && cc.Destination != "" {
for _, p := range utils.SplitPrefix(cc.Destination, MIN_PREFIX_MATCH) {
if destIDs, err := ratingStorage.GetReverseDestination(p, false, utils.NonTransactional); err == nil {
for _, dID := range destIDs {
if _, ok := (*bf.DestinationIDs)[dID]; ok {
foundMatchingDestID = true
break // only one found?
}
}
}
if foundMatchingDestID {
break
}
}
} else {
foundMatchingDestID = true
}
if !foundMatchingDestID {
return false
}
return true
}
示例4: addUnits
// Adds the units from the received balance to an existing balance if the destination
// is the same or ads the balance to the list if none matches.
func (uc *UnitsCounter) addUnits(amount float64, prefix string) {
counted := false
if prefix != "" {
for _, mb := range uc.Balances {
if !mb.HasDestination() {
continue
}
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil {
destIds := x.([]interface{})
for _, dId := range destIds {
if dId == mb.DestinationId {
mb.Value += amount
counted = true
break
}
}
}
if counted {
break
}
}
}
}
if !counted {
// use general balance
b := uc.GetGeneralBalance()
b.Value += amount
}
}
示例5: MatchCCFilter
func (b *Balance) MatchCCFilter(cc *CallCost) bool {
if len(b.Categories) > 0 && cc.Category != "" && b.Categories[cc.Category] == false {
return false
}
if len(b.Directions) > 0 && cc.Direction != "" && b.Directions[cc.Direction] == false {
return false
}
// match destination ids
foundMatchingDestId := false
if len(b.DestinationIds) > 0 && cc.Destination != "" {
for _, p := range utils.SplitPrefix(cc.Destination, MIN_PREFIX_MATCH) {
if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
for filterDestId := range b.DestinationIds {
if _, ok := destIds[filterDestId]; ok {
foundMatchingDestId = true
break
}
}
}
if foundMatchingDestId {
break
}
}
} else {
foundMatchingDestId = true
}
if !foundMatchingDestId {
return false
}
return true
}
示例6: GetLCREntryForPrefix
func (lcra *LCRActivation) GetLCREntryForPrefix(destination string) *LCREntry {
var potentials LCREntriesSorter
for _, p := range utils.SplitPrefix(destination, MIN_PREFIX_MATCH) {
if destIDs, err := ratingStorage.GetReverseDestination(p, true, utils.NonTransactional); err == nil {
for _, dId := range destIDs {
for _, entry := range lcra.Entries {
if entry.DestinationId == dId {
entry.precision = len(p)
potentials = append(potentials, entry)
}
}
}
}
}
if len(potentials) > 0 {
// sort by precision and weight
potentials.Sort()
return potentials[0]
}
// return the *any entry if it exists
for _, entry := range lcra.Entries {
if entry.DestinationId == utils.ANY {
return entry
}
}
return nil
}
示例7: getBalancesForPrefix
func (ub *Account) getBalancesForPrefix(prefix, category, direction, tor string, sharedGroup string) BalanceChain {
var balances BalanceChain
balances = append(balances, ub.BalanceMap[tor]...)
if tor != utils.MONETARY && tor != utils.GENERIC {
balances = append(balances, ub.BalanceMap[utils.GENERIC]...)
}
var usefulBalances BalanceChain
for _, b := range balances {
if b.Disabled {
continue
}
if b.IsExpired() || (len(b.SharedGroups) == 0 && b.GetValue() <= 0) {
continue
}
if sharedGroup != "" && b.SharedGroups[sharedGroup] == false {
continue
}
if !b.MatchCategory(category) {
continue
}
if b.HasDirection() && b.Directions[direction] == false {
continue
}
b.account = ub
if len(b.DestinationIds) > 0 && b.DestinationIds[utils.ANY] == false {
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
for dId, _ := range destIds {
if b.DestinationIds[dId.(string)] == true {
b.precision = len(p)
usefulBalances = append(usefulBalances, b)
break
}
if b.precision > 0 {
break
}
}
}
if b.precision > 0 {
break
}
}
} else {
usefulBalances = append(usefulBalances, b)
}
}
// resort by precision
usefulBalances.Sort()
// clear precision
for _, b := range usefulBalances {
b.precision = 0
}
return usefulBalances
}
示例8: GetMatchingAlias
func (am *AliasHandler) GetMatchingAlias(attr AttrMatchingAlias, result *string) error {
response := Alias{}
if err := am.GetAlias(Alias{
Direction: attr.Direction,
Tenant: attr.Tenant,
Category: attr.Category,
Account: attr.Account,
Subject: attr.Subject,
Context: attr.Context,
}, &response); err != nil {
return err
}
// sort according to weight
values := response.Values
values.Sort()
// if destination does not metter get first alias
if attr.Destination == "" || attr.Destination == utils.ANY {
for _, value := range values {
if origAlias, ok := value.Pairs[attr.Target]; ok {
if alias, ok := origAlias[attr.Original]; ok {
*result = alias
return nil
}
}
}
return utils.ErrNotFound
}
// check destination ids
for _, p := range utils.SplitPrefix(attr.Destination, MIN_PREFIX_MATCH) {
if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
for _, value := range values {
for idId := range destIds {
dId := idId.(string)
if value.DestinationId == utils.ANY || value.DestinationId == dId {
if origAliasMap, ok := value.Pairs[attr.Target]; ok {
if alias, ok := origAliasMap[attr.Original]; ok || attr.Original == "" || attr.Original == utils.ANY {
*result = alias
return nil
}
if alias, ok := origAliasMap[utils.ANY]; ok {
*result = alias
return nil
}
}
}
}
}
}
}
return utils.ErrNotFound
}
示例9: GetMatchingAlias
func (am *AliasHandler) GetMatchingAlias(attr *AttrMatchingAlias, result *string) error {
response := Alias{}
if err := am.GetAlias(&Alias{
Direction: attr.Direction,
Tenant: attr.Tenant,
Category: attr.Category,
Account: attr.Account,
Subject: attr.Subject,
Context: attr.Context,
}, &response); err != nil {
return err
}
// sort according to weight
values := response.Values
values.Sort()
// if destination does not metter get first alias
if attr.Destination == "" || attr.Destination == utils.ANY {
for _, value := range values {
if origAlias, ok := value.Pairs[attr.Target]; ok {
if alias, ok := origAlias[attr.Original]; ok {
*result = alias
return nil
}
}
}
return utils.ErrNotFound
}
// check destination ids
for _, p := range utils.SplitPrefix(attr.Destination, MIN_PREFIX_MATCH) {
if destIDs, err := ratingStorage.GetReverseDestination(p, false, utils.NonTransactional); err == nil {
for _, value := range values {
for _, dId := range destIDs {
if value.DestinationId == utils.ANY || value.DestinationId == dId {
if origAliasMap, ok := value.Pairs[attr.Target]; ok {
if alias, ok := origAliasMap[attr.Original]; ok || attr.Original == "" || attr.Original == utils.ANY {
*result = alias
return nil
}
if alias, ok := origAliasMap[utils.ANY]; ok {
*result = alias
return nil
}
}
}
}
}
}
}
return utils.ErrNotFound
}
示例10: getBalancesForPrefix
func (ub *Account) getBalancesForPrefix(prefix, category string, balances BalanceChain, sharedGroup string) BalanceChain {
var usefulBalances BalanceChain
for _, b := range balances {
if b.Disabled {
continue
}
if b.IsExpired() || (b.SharedGroup == "" && b.GetValue() <= 0) {
continue
}
if sharedGroup != "" && b.SharedGroup != sharedGroup {
continue
}
if !b.MatchCategory(category) {
continue
}
b.account = ub
if b.DestinationIds != "" && b.DestinationIds != utils.ANY {
balDestIds := strings.Split(b.DestinationIds, utils.INFIELD_SEP)
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
for dId, _ := range destIds {
for _, balDestID := range balDestIds {
if dId == strings.TrimSpace(balDestID) {
b.precision = len(p)
usefulBalances = append(usefulBalances, b)
break
}
}
if b.precision > 0 {
break
}
}
}
if b.precision > 0 {
break
}
}
} else {
usefulBalances = append(usefulBalances, b)
}
}
// resort by precision
usefulBalances.Sort()
// clear precision
for _, b := range usefulBalances {
b.precision = 0
}
return usefulBalances
}
示例11: getMatchingPrefixAndDestID
func (b *Balance) getMatchingPrefixAndDestID(dest string) (prefix, destId string) {
if len(b.DestinationIDs) != 0 && b.DestinationIDs[utils.ANY] == false {
for _, p := range utils.SplitPrefix(dest, MIN_PREFIX_MATCH) {
if destIDs, err := ratingStorage.GetReverseDestination(p, false, utils.NonTransactional); err == nil {
for _, dID := range destIDs {
if b.DestinationIDs[dID] == true {
return p, dID
}
}
}
}
}
return
}
示例12: getMatchingPrefixAndDestID
func (b *Balance) getMatchingPrefixAndDestID(dest string) (prefix, destId string) {
if len(b.DestinationIDs) != 0 && b.DestinationIDs[utils.ANY] == false {
for _, p := range utils.SplitPrefix(dest, MIN_PREFIX_MATCH) {
if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
destIDs := x.(map[string]struct{})
for dID := range destIDs {
if b.DestinationIDs[dID] == true {
return p, dID
}
}
}
}
}
return
}
示例13: getMatchingPrefixAndDestId
func (b *Balance) getMatchingPrefixAndDestId(dest string) (prefix, destId string) {
if len(b.DestinationIds) != 0 && b.DestinationIds[utils.ANY] == false {
for _, p := range utils.SplitPrefix(dest, MIN_PREFIX_MATCH) {
if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
for dId, _ := range destIds {
if b.DestinationIds[dId.(string)] == true {
return p, dId.(string)
}
}
}
}
}
return
}
示例14: DerivedChargersMatchesDest
func DerivedChargersMatchesDest(dcs *utils.DerivedChargers, dest string) bool {
if len(dcs.DestinationIDs) == 0 || dcs.DestinationIDs[utils.ANY] {
return true
}
// check destination ids
for _, p := range utils.SplitPrefix(dest, MIN_PREFIX_MATCH) {
if destIDs, err := ratingStorage.GetReverseDestination(p, false, utils.NonTransactional); err == nil {
for _, dId := range destIDs {
includeDest, found := dcs.DestinationIDs[dId]
if found {
return includeDest
}
}
}
}
return false
}
示例15: DerivedChargersMatchesDest
func DerivedChargersMatchesDest(dcs *utils.DerivedChargers, dest string) bool {
if len(dcs.DestinationIDs) == 0 || dcs.DestinationIDs[utils.ANY] {
return true
}
// check destination ids
for _, p := range utils.SplitPrefix(dest, MIN_PREFIX_MATCH) {
if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[string]struct{})
for dId := range destIds {
includeDest, found := dcs.DestinationIDs[dId]
if found {
return includeDest
}
}
}
}
return false
}