本文整理匯總了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
}
示例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
}
示例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
//.........這裏部分代碼省略.........