• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang utils.SplitPrefix函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cgrates/cgrates/utils.SplitPrefix函数的典型用法代码示例。如果您正苦于以下问题:Golang SplitPrefix函数的具体用法?Golang SplitPrefix怎么用?Golang SplitPrefix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了SplitPrefix函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: getMatchingPrefixAndDestId

func (b *Balance) getMatchingPrefixAndDestId(dest string) (prefix, destId string) {
	if b.DestinationIds != "" && b.DestinationIds != utils.ANY {
		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 {
					balDestIds := strings.Split(b.DestinationIds, utils.INFIELD_SEP)
					for _, balDestID := range balDestIds {
						if dId == balDestID {
							return p, balDestID
						}
					}

				}
			}
		}
	}
	return
}
开发者ID:nikbyte,项目名称:cgrates,代码行数:19,代码来源:balances.go


示例17: passDestinations

func (fltr *RequestFilter) passDestinations(req interface{}, extraFieldsLabel string) (bool, error) {
	dst, err := utils.ReflectFieldAsString(req, fltr.FieldName, extraFieldsLabel)
	if err != nil {
		return false, err
	}
	for _, p := range utils.SplitPrefix(dst, MIN_PREFIX_MATCH) {
		if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
			destIds := x.(map[string]struct{})
			for dID := range destIds {
				for _, valDstID := range fltr.Values {
					if valDstID == dID {
						return true, nil
					}
				}
			}
		}
	}
	return false, nil
}
开发者ID:iwada,项目名称:cgrates,代码行数:19,代码来源:reqfilter.go


示例18: 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 := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
			destIds := x.(map[interface{}]struct{})
			for value := range dcs.DestinationIds {
				for idId := range destIds {
					dId := idId.(string)
					if value == dId {
						return true
					}
				}
			}
		}
	}
	return false
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:20,代码来源:handler_derivedcharging.go


示例19: getBalancesForPrefix

func (ub *Account) getBalancesForPrefix(prefix, category string, balances BalanceChain, sharedGroup string) BalanceChain {
	var usefulBalances BalanceChain
	for _, b := range balances {
		if b.IsExpired() || (ub.AllowNegative == false && b.SharedGroup == "" && b.Value <= 0) {
			continue
		}
		if sharedGroup != "" && b.SharedGroup != sharedGroup {
			continue
		}
		if !b.MatchCategory(category) {
			continue
		}
		b.account = ub
		if b.DestinationId != "" && b.DestinationId != utils.ANY {
			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 == b.DestinationId {
							b.precision = len(p)
							usefulBalances = append(usefulBalances, b)
							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:intralanman,项目名称:cgrates,代码行数:41,代码来源:account.go


示例20: passDestinations

func (fltr *RequestFilter) passDestinations(req interface{}, extraFieldsLabel string) (bool, error) {
	dst, err := utils.ReflectFieldAsString(req, fltr.FieldName, extraFieldsLabel)
	if err != nil {
		if err == utils.ErrNotFound {
			return false, nil
		}
		return false, err
	}
	for _, p := range utils.SplitPrefix(dst, MIN_PREFIX_MATCH) {
		if destIDs, err := ratingStorage.GetReverseDestination(p, false, utils.NonTransactional); err == nil {
			for _, dID := range destIDs {
				for _, valDstID := range fltr.Values {
					if valDstID == dID {
						return true, nil
					}
				}
			}
		}
	}
	return false, nil
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:21,代码来源:reqfilter.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang utils.StringMapPointer函数代码示例发布时间:2022-05-23
下一篇:
Golang utils.Sha1函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap