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

Golang rpcclient.RpcClientConnection类代码示例

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

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



在下文中一共展示了RpcClientConnection类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: cgrRPCAction

/*
<< .Object.Property >>

Property can be a attribute or a method both used without ()
Please also note the initial dot .

Currently there are following objects that can be used:

Account -  the account that this action is called on
Action - the action with all it's attributs
Actions - the list of actions in the current action set
Sq - StatsQueueTriggered object

We can actually use everythiong that go templates offer. You can read more here: https://golang.org/pkg/text/template/
*/
func cgrRPCAction(account *Account, sq *StatsQueueTriggered, a *Action, acs Actions) error {
	// parse template
	tmpl := template.New("extra_params")
	tmpl.Delims("<<", ">>")
	t, err := tmpl.Parse(a.ExtraParameters)
	if err != nil {
		utils.Logger.Err(fmt.Sprintf("error parsing *cgr_rpc template: %s", err.Error()))
		return err
	}
	var buf bytes.Buffer
	if err = t.Execute(&buf, struct {
		Account *Account
		Sq      *StatsQueueTriggered
		Action  *Action
		Actions Actions
	}{account, sq, a, acs}); err != nil {
		utils.Logger.Err(fmt.Sprintf("error executing *cgr_rpc template %s:", err.Error()))
		return err
	}
	processedExtraParam := buf.String()
	//utils.Logger.Info("ExtraParameters: " + parsedExtraParameters)
	req := RPCRequest{}
	if err := json.Unmarshal([]byte(processedExtraParam), &req); err != nil {
		return err
	}
	params, err := utils.GetRpcParams(req.Method)
	if err != nil {
		return err
	}
	var client rpcclient.RpcClientConnection
	if req.Address != utils.MetaInternal {
		if client, err = rpcclient.NewRpcClient("tcp", req.Address, req.Attempts, 0, config.CgrConfig().ConnectTimeout, config.CgrConfig().ReplyTimeout, req.Transport, nil); err != nil {
			return err
		}
	} else {
		client = params.Object.(rpcclient.RpcClientConnection)
	}
	in, out := params.InParam, params.OutParam
	//utils.Logger.Info("Params: " + utils.ToJSON(req.Params))
	//p, err := utils.FromMapStringInterfaceValue(req.Params, in)
	mapstructure.Decode(req.Params, in)
	if err != nil {
		utils.Logger.Info("<*cgr_rpc> err: " + err.Error())
		return err
	}
	utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> calling: %s with: %s", req.Method, utils.ToJSON(in)))
	if !req.Async {
		err = client.Call(req.Method, in, out)
		utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> result: %s err: %v", utils.ToJSON(out), err))
		return err
	}
	go func() {
		err := client.Call(req.Method, in, out)
		utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> result: %s err: %v", utils.ToJSON(out), err))
	}()
	return nil
}
开发者ID:iwada,项目名称:cgrates,代码行数:72,代码来源:action.go


示例2: passCDRStats

func (fltr *RequestFilter) passCDRStats(req interface{}, extraFieldsLabel string, cdrStats rpcclient.RpcClientConnection) (bool, error) {
	if cdrStats == nil {
		return false, errors.New("Missing CDRStatS information")
	}
	for _, threshold := range fltr.cdrStatSThresholds {
		statValues := make(map[string]float64)
		if err := cdrStats.Call("CDRStatsV1.GetValues", threshold.QueueID, &statValues); err != nil {
			return false, err
		}
		if val, hasIt := statValues[threshold.ThresholdType[len(MetaMinCapPrefix):]]; !hasIt {
			continue
		} else if strings.HasPrefix(threshold.ThresholdType, MetaMinCapPrefix) && val >= threshold.ThresholdValue {
			return true, nil
		} else if strings.HasPrefix(threshold.ThresholdType, MetaMaxCapPrefix) && val < threshold.ThresholdValue {
			return true, nil
		}
	}
	return false, nil
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:19,代码来源:reqfilter.go


示例3: GetLCR

func (cd *CallDescriptor) GetLCR(stats rpcclient.RpcClientConnection, lcrFltr *LCRFilter, p *utils.Paginator) (*LCRCost, error) {
	cd.account = nil // make sure it's not cached
	lcr, err := cd.GetLCRFromStorage()
	if err != nil {
		return nil, err
	}
	// sort by activation time
	lcr.Sort()
	// find if one ore more entries apply to this cd (create lcr timespans)
	// create timespans and attach lcr entries to them
	lcrCost := &LCRCost{}
	for _, lcrActivation := range lcr.Activations {
		lcrEntry := lcrActivation.GetLCREntryForPrefix(cd.Destination)
		if lcrActivation.ActivationTime.Before(cd.TimeStart) ||
			lcrActivation.ActivationTime.Equal(cd.TimeStart) {
			lcrCost.Entry = lcrEntry
		} else {
			// because lcr is sorted the folowing ones will
			// only activate later than cd.Timestart
			break
		}
	}
	if lcrCost.Entry == nil {
		return lcrCost, nil
	}
	if lcrCost.Entry.Strategy == LCR_STRATEGY_STATIC {
		for _, supplier := range lcrCost.Entry.GetParams() {
			lcrCD := cd.Clone()
			lcrCD.Account = supplier
			lcrCD.Subject = supplier
			lcrCD.Category = lcrCost.Entry.RPCategory
			fullSupplier := utils.ConcatenatedKey(lcrCD.Direction, lcrCD.Tenant, lcrCD.Category, lcrCD.Subject)
			var cc *CallCost
			var err error
			if cd.account, err = accountingStorage.GetAccount(lcrCD.GetAccountKey()); err == nil {
				if cd.account.Disabled {
					lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{
						Supplier: fullSupplier,
						Error:    fmt.Sprintf("supplier %s is disabled", supplier),
					})
					continue
				}
				cc, err = lcrCD.debit(cd.account, true, true)
			} else {
				cc, err = lcrCD.GetCost()
			}
			//log.Printf("CC: %+v", cc.Timespans[0].ratingInfo.RateIntervals[0].Rating.Rates[0])
			if err != nil || cc == nil {
				lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{
					Supplier: fullSupplier,
					Error:    err.Error(),
				})
			} else {
				lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{
					Supplier: fullSupplier,
					Cost:     cc.Cost,
					Duration: cc.GetDuration(),
				})
			}
		}
	} else {
		// find rating profiles
		category := lcrCost.Entry.RPCategory
		if category == utils.META_DEFAULT {
			category = lcr.Category
		}
		ratingProfileSearchKey := utils.ConcatenatedKey(lcr.Direction, lcr.Tenant, lcrCost.Entry.RPCategory)
		searchKey := utils.RATING_PROFILE_PREFIX + ratingProfileSearchKey
		suppliers := cache.GetEntryKeys(searchKey)
		if len(suppliers) == 0 { // Most probably the data was not cached, do it here, #ToDo: move logic in RAL service
			suppliers, err = ratingStorage.GetKeysForPrefix(searchKey)
			if err != nil {
				return nil, err
			}
			transID := utils.GenUUID()
			for _, dbKey := range suppliers {
				if _, err := ratingStorage.GetRatingProfile(dbKey[len(utils.RATING_PROFILE_PREFIX):], true, transID); err != nil { // cache the keys here
					cache.RollbackTransaction(transID)
					return nil, err
				}
			}
			cache.CommitTransaction(transID)
		}
		for _, supplier := range suppliers {
			split := strings.Split(supplier, ":")
			supplier = split[len(split)-1]
			lcrCD := cd.Clone()
			lcrCD.Category = category
			lcrCD.Account = supplier
			lcrCD.Subject = supplier
			fullSupplier := utils.ConcatenatedKey(lcrCD.Direction, lcrCD.Tenant, lcrCD.Category, lcrCD.Subject)
			var qosSortParams []string
			var asrValues sort.Float64Slice
			var pddValues sort.Float64Slice
			var acdValues sort.Float64Slice
			var tcdValues sort.Float64Slice
			var accValues sort.Float64Slice
			var tccValues sort.Float64Slice
			var ddcValues sort.Float64Slice
			// track if one value is never calculated
//.........这里部分代码省略.........
开发者ID:cgrates,项目名称:cgrates,代码行数:101,代码来源:calldesc.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang girl.Context类代码示例发布时间:2022-05-23
下一篇:
Golang rpcclient.NewRpcClient函数代码示例发布时间: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