当前位置: 首页>>代码示例>>Golang>>正文


Golang utils.SplitPrefix函数代码示例

本文整理汇总了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)
	}
}
开发者ID:nikbyte,项目名称:cgrates,代码行数:30,代码来源:units_counter.go

示例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
}
开发者ID:iwada,项目名称:cgrates,代码行数:29,代码来源:lcr.go

示例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
}
开发者ID:cgrates,项目名称:cgrates,代码行数:35,代码来源:callcost.go

示例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
	}
}
开发者ID:intralanman,项目名称:cgrates,代码行数:32,代码来源:units_counter.go

示例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
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:33,代码来源:balances.go

示例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
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:27,代码来源:lcr.go

示例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
}
开发者ID:perrault,项目名称:cgrates,代码行数:55,代码来源:account.go

示例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
}
开发者ID:perrault,项目名称:cgrates,代码行数:53,代码来源:aliases.go

示例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
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:51,代码来源:aliases.go

示例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
}
开发者ID:nikbyte,项目名称:cgrates,代码行数:50,代码来源:account.go

示例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
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:14,代码来源:balances.go

示例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
}
开发者ID:iwada,项目名称:cgrates,代码行数:15,代码来源:balances.go

示例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
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:15,代码来源:balances.go

示例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
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:17,代码来源:handler_derivedcharging.go

示例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
}
开发者ID:iwada,项目名称:cgrates,代码行数:18,代码来源:handler_derivedcharging.go


注:本文中的github.com/cgrates/cgrates/utils.SplitPrefix函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。