當前位置: 首頁>>代碼示例>>Golang>>正文


Golang CDR.CGRID方法代碼示例

本文整理匯總了Golang中github.com/cgrates/cgrates/engine.CDR.CGRID方法的典型用法代碼示例。如果您正苦於以下問題:Golang CDR.CGRID方法的具體用法?Golang CDR.CGRID怎麽用?Golang CDR.CGRID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cgrates/cgrates/engine.CDR的用法示例。


在下文中一共展示了CDR.CGRID方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: AsStoredCdr

func (kev KamEvent) AsStoredCdr(timezone string) *engine.CDR {
	storCdr := new(engine.CDR)
	storCdr.CGRID = kev.GetCgrId(timezone)
	storCdr.ToR = utils.VOICE
	storCdr.OriginID = kev.GetUUID()
	storCdr.OriginHost = kev.GetOriginatorIP(utils.META_DEFAULT)
	storCdr.Source = kev.GetCdrSource()
	storCdr.RequestType = kev.GetReqType(utils.META_DEFAULT)
	storCdr.Direction = kev.GetDirection(utils.META_DEFAULT)
	storCdr.Tenant = kev.GetTenant(utils.META_DEFAULT)
	storCdr.Category = kev.GetCategory(utils.META_DEFAULT)
	storCdr.Account = kev.GetAccount(utils.META_DEFAULT)
	storCdr.Subject = kev.GetSubject(utils.META_DEFAULT)
	storCdr.Destination = kev.GetDestination(utils.META_DEFAULT)
	storCdr.SetupTime, _ = kev.GetSetupTime(utils.META_DEFAULT, timezone)
	storCdr.AnswerTime, _ = kev.GetAnswerTime(utils.META_DEFAULT, timezone)
	storCdr.Usage, _ = kev.GetDuration(utils.META_DEFAULT)
	storCdr.PDD, _ = kev.GetPdd(utils.META_DEFAULT)
	storCdr.Supplier = kev.GetSupplier(utils.META_DEFAULT)
	storCdr.DisconnectCause = kev.GetDisconnectCause(utils.META_DEFAULT)
	storCdr.ExtraFields = kev.GetExtraFields()
	storCdr.Cost = -1

	return storCdr
}
開發者ID:bhepp,項目名稱:cgrates,代碼行數:25,代碼來源:kamevent.go

示例2: recordToStoredCdr

// Converts a record (header or normal) to CDR
func (self *FwvRecordsProcessor) recordToStoredCdr(record string, cdrcCfg *config.CdrcConfig, cfgKey string) (*engine.CDR, error) {
	var err error
	var lazyHttpFields []*config.CfgCdrField
	var cfgFields []*config.CfgCdrField
	var duMultiplyFactor float64
	var storedCdr *engine.CDR
	if self.headerCdr != nil { // Clone the header CDR so we can use it as base to future processing (inherit fields defined there)
		storedCdr = self.headerCdr.Clone()
	} else {
		storedCdr = &engine.CDR{OriginHost: "0.0.0.0", ExtraFields: make(map[string]string), Cost: -1}
	}
	if cfgKey == "*header" {
		cfgFields = cdrcCfg.HeaderFields
		storedCdr.Source = cdrcCfg.CdrSourceId
		duMultiplyFactor = cdrcCfg.DataUsageMultiplyFactor
	} else {
		cfgFields = cdrcCfg.ContentFields
		storedCdr.Source = cdrcCfg.CdrSourceId
		duMultiplyFactor = cdrcCfg.DataUsageMultiplyFactor
	}
	for _, cdrFldCfg := range cfgFields {
		var fieldVal string
		switch cdrFldCfg.Type {
		case utils.META_COMPOSED:
			for _, cfgFieldRSR := range cdrFldCfg.Value {
				if cfgFieldRSR.IsStatic() {
					fieldVal += cfgFieldRSR.ParseValue("")
				} else { // Dynamic value extracted using index
					if cfgFieldIdx, _ := strconv.Atoi(cfgFieldRSR.Id); len(record) <= cfgFieldIdx {
						return nil, fmt.Errorf("Ignoring record: %v - cannot extract field %s", record, cdrFldCfg.Tag)
					} else {
						fieldVal += cfgFieldRSR.ParseValue(fwvValue(record, cfgFieldIdx, cdrFldCfg.Width, cdrFldCfg.Padding))
					}
				}
			}
		case utils.META_HTTP_POST:
			lazyHttpFields = append(lazyHttpFields, cdrFldCfg) // Will process later so we can send an estimation of storedCdr to http server
		default:
			//return nil, fmt.Errorf("Unsupported field type: %s", cdrFldCfg.Type)
			continue // Don't do anything for unsupported fields
		}
		if err := storedCdr.ParseFieldValue(cdrFldCfg.FieldId, fieldVal, self.timezone); err != nil {
			return nil, err
		}
	}
	if storedCdr.CGRID == "" && storedCdr.OriginID != "" && cfgKey != "*header" {
		storedCdr.CGRID = utils.Sha1(storedCdr.OriginID, storedCdr.SetupTime.UTC().String())
	}
	if storedCdr.ToR == utils.DATA && duMultiplyFactor != 0 {
		storedCdr.Usage = time.Duration(float64(storedCdr.Usage.Nanoseconds()) * duMultiplyFactor)
	}
	for _, httpFieldCfg := range lazyHttpFields { // Lazy process the http fields
		var outValByte []byte
		var fieldVal, httpAddr string
		for _, rsrFld := range httpFieldCfg.Value {
			httpAddr += rsrFld.ParseValue("")
		}
		var jsn []byte
		jsn, err = json.Marshal(storedCdr)
		if err != nil {
			return nil, err
		}
		if outValByte, err = utils.HttpJsonPost(httpAddr, self.httpSkipTlsCheck, jsn); err != nil && httpFieldCfg.Mandatory {
			return nil, err
		} else {
			fieldVal = string(outValByte)
			if len(fieldVal) == 0 && httpFieldCfg.Mandatory {
				return nil, fmt.Errorf("MandatoryIeMissing: Empty result for http_post field: %s", httpFieldCfg.Tag)
			}
			if err := storedCdr.ParseFieldValue(httpFieldCfg.FieldId, fieldVal, self.timezone); err != nil {
				return nil, err
			}
		}
	}
	return storedCdr, nil
}
開發者ID:iwada,項目名稱:cgrates,代碼行數:77,代碼來源:fwv.go


注:本文中的github.com/cgrates/cgrates/engine.CDR.CGRID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。