本文整理汇总了Golang中github.com/cgrates/cgrates/utils.FirstNonEmpty函数的典型用法代码示例。如果您正苦于以下问题:Golang FirstNonEmpty函数的具体用法?Golang FirstNonEmpty怎么用?Golang FirstNonEmpty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FirstNonEmpty函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetSubject
func (fsev FSEvent) GetSubject(fieldName string) string {
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
} else if fieldName == utils.META_DEFAULT {
return utils.FirstNonEmpty(fsev[SUBJECT], fsev[USERNAME])
}
return utils.FirstNonEmpty(fsev[fieldName], fsev[SUBJECT], fsev[USERNAME])
}
开发者ID:intralanman,项目名称:cgrates,代码行数:8,代码来源:fsevent.go
示例2: GetDestination
// Charging destination number
func (fsev FSEvent) GetDestination(fieldName string) string {
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
} else if fieldName == utils.META_DEFAULT {
return utils.FirstNonEmpty(fsev[DESTINATION], fsev[CALL_DEST_NR])
}
return utils.FirstNonEmpty(fsev[fieldName], fsev[DESTINATION], fsev[CALL_DEST_NR])
}
开发者ID:intralanman,项目名称:cgrates,代码行数:9,代码来源:fsevent.go
示例3: GetReqType
func (fsev FSEvent) GetReqType(fieldName string) string {
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
} else if fieldName == utils.META_DEFAULT {
return utils.FirstNonEmpty(fsev[REQTYPE], config.CgrConfig().DefaultReqType)
}
return utils.FirstNonEmpty(fsev[fieldName], fsev[REQTYPE], config.CgrConfig().DefaultReqType)
}
开发者ID:intralanman,项目名称:cgrates,代码行数:8,代码来源:fsevent.go
示例4: AsStoredCdr
func (fsCdr FSCdr) AsStoredCdr(timezone string) *CDR {
storCdr := new(CDR)
storCdr.CGRID = fsCdr.getCGRID(timezone)
storCdr.ToR = utils.VOICE
storCdr.OriginID = fsCdr.vars[FS_UUID]
storCdr.OriginHost = fsCdr.vars[FS_IP]
storCdr.Source = FS_CDR_SOURCE
storCdr.RequestType = utils.FirstNonEmpty(fsCdr.vars[utils.CGR_REQTYPE], fsCdr.cgrCfg.DefaultReqType)
storCdr.Direction = utils.OUT
storCdr.Tenant = utils.FirstNonEmpty(fsCdr.vars[utils.CGR_TENANT], fsCdr.cgrCfg.DefaultTenant)
storCdr.Category = utils.FirstNonEmpty(fsCdr.vars[utils.CGR_CATEGORY], fsCdr.cgrCfg.DefaultCategory)
storCdr.Account = utils.FirstNonEmpty(fsCdr.vars[utils.CGR_ACCOUNT], fsCdr.vars[FS_USERNAME])
storCdr.Subject = utils.FirstNonEmpty(fsCdr.vars[utils.CGR_SUBJECT], fsCdr.vars[utils.CGR_ACCOUNT], fsCdr.vars[FS_USERNAME])
storCdr.Destination = utils.FirstNonEmpty(fsCdr.vars[utils.CGR_DESTINATION], fsCdr.vars[FS_CALL_DEST_NR], fsCdr.vars[FS_SIP_REQUSER])
storCdr.SetupTime, _ = utils.ParseTimeDetectLayout(fsCdr.vars[FS_SETUP_TIME], timezone) // Not interested to process errors, should do them if necessary in a previous step
pddStr := utils.FirstNonEmpty(fsCdr.vars[FS_PROGRESS_MEDIAMSEC], fsCdr.vars[FS_PROGRESSMS])
pddStr += "ms"
storCdr.PDD, _ = time.ParseDuration(pddStr)
storCdr.AnswerTime, _ = utils.ParseTimeDetectLayout(fsCdr.vars[FS_ANSWER_TIME], timezone)
storCdr.Usage, _ = utils.ParseDurationWithSecs(fsCdr.vars[FS_DURATION])
storCdr.Supplier = fsCdr.vars[utils.CGR_SUPPLIER]
storCdr.DisconnectCause = utils.FirstNonEmpty(fsCdr.vars[utils.CGR_DISCONNECT_CAUSE], fsCdr.vars["hangup_cause"])
storCdr.ExtraFields = fsCdr.getExtraFields()
storCdr.Cost = -1
return storCdr
}
开发者ID:bhepp,项目名称:cgrates,代码行数:26,代码来源:fscdr.go
示例5: GetSetupTime
func (kev KamEvent) GetSetupTime(fieldName, timezone string) (time.Time, error) {
sTimeStr := utils.FirstNonEmpty(kev[fieldName], kev[CGR_SETUPTIME], kev[CGR_ANSWERTIME])
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
sTimeStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
}
return utils.ParseTimeDetectLayout(sTimeStr, timezone)
}
开发者ID:bhepp,项目名称:cgrates,代码行数:7,代码来源:kamevent.go
示例6: GetSetupTime
func (osipsev *OsipsEvent) GetSetupTime(fieldName, timezone string) (time.Time, error) {
sTimeStr := utils.FirstNonEmpty(osipsev.osipsEvent.AttrValues[fieldName], osipsev.osipsEvent.AttrValues[OSIPS_SETUP_TIME], osipsev.osipsEvent.AttrValues[OSIPS_EVENT_TIME])
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
sTimeStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
}
return utils.ParseTimeDetectLayout(sTimeStr, timezone)
}
开发者ID:iwada,项目名称:cgrates,代码行数:7,代码来源:osipsevent.go
示例7: GetDuration
func (kev KamEvent) GetDuration(fieldName string) (time.Duration, error) {
durStr := utils.FirstNonEmpty(kev[fieldName], kev[CGR_DURATION])
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
durStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
}
return utils.ParseDurationWithSecs(durStr)
}
开发者ID:bhepp,项目名称:cgrates,代码行数:7,代码来源:kamevent.go
示例8: GetDuration
func (osipsev *OsipsEvent) GetDuration(fieldName string) (time.Duration, error) {
durStr := utils.FirstNonEmpty(osipsev.osipsEvent.AttrValues[fieldName], osipsev.osipsEvent.AttrValues[OSIPS_DURATION])
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
durStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
}
return utils.ParseDurationWithSecs(durStr)
}
开发者ID:iwada,项目名称:cgrates,代码行数:7,代码来源:osipsevent.go
示例9: GetOriginatorIP
func (fsev FSEvent) GetOriginatorIP(fieldName string) string {
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
} else if fieldName == utils.META_DEFAULT {
return fsev[FS_IPv4]
}
return utils.FirstNonEmpty(fsev[fieldName], fsev[FS_IPv4])
}
开发者ID:intralanman,项目名称:cgrates,代码行数:8,代码来源:fsevent.go
示例10: GetAnswerTime
func (osipsev *OsipsEvent) GetAnswerTime(fieldName, timezone string) (time.Time, error) {
aTimeStr := utils.FirstNonEmpty(osipsev.osipsEvent.AttrValues[fieldName], osipsev.osipsEvent.AttrValues[CGR_ANSWERTIME])
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
aTimeStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
} else if fieldName == utils.META_DEFAULT {
aTimeStr = osipsev.osipsEvent.AttrValues[CGR_ANSWERTIME]
}
return utils.ParseTimeDetectLayout(aTimeStr, timezone)
}
开发者ID:iwada,项目名称:cgrates,代码行数:9,代码来源:osipsevent.go
示例11: GetAnswerTime
func (fsev FSEvent) GetAnswerTime(fieldName, timezone string) (t time.Time, err error) {
fsATimeStr, hasKey := fsev[ANSWER_TIME]
if hasKey && fsATimeStr != "0" {
// Discard the nanoseconds information since MySQL cannot store them in early versions and csv uses default seconds so cgrid will not corelate
fsATimeStr = fsATimeStr[:len(fsATimeStr)-6]
}
aTimeStr := utils.FirstNonEmpty(fsev[fieldName], fsATimeStr)
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
aTimeStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
}
return utils.ParseTimeDetectLayout(aTimeStr, timezone)
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:12,代码来源:fsevent.go
示例12: GetReqType
func (fsev FSEvent) GetReqType(fieldName string) string {
var reqTypeDetected = "" // Used to automatically disable processing of the request
if fsev["variable_process_cdr"] == "false" { // FS will not generated CDR here
reqTypeDetected = utils.META_NONE
} else if fsev["Caller-Dialplan"] == "inline" { // Used for internally generated dialplan, eg refer coming from another box, not in our control
reqTypeDetected = utils.META_NONE
}
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
}
return utils.FirstNonEmpty(fsev[fieldName], fsev[REQTYPE], reqTypeDetected, config.CgrConfig().DefaultReqType)
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:12,代码来源:fsevent.go
示例13: AsCallDescriptor
// Converts into CallDescriptor due to responder interface needs
func (kev KamEvent) AsCallDescriptor() (*engine.CallDescriptor, error) {
lcrReq := &engine.LcrRequest{
Direction: kev.GetDirection(utils.META_DEFAULT),
Tenant: kev.GetTenant(utils.META_DEFAULT),
Category: kev.GetCategory(utils.META_DEFAULT),
Account: kev.GetAccount(utils.META_DEFAULT),
Subject: kev.GetSubject(utils.META_DEFAULT),
Destination: kev.GetDestination(utils.META_DEFAULT),
SetupTime: utils.FirstNonEmpty(kev[CGR_SETUPTIME], kev[CGR_ANSWERTIME]),
Duration: kev[CGR_DURATION],
}
return lcrReq.AsCallDescriptor(config.CgrConfig().DefaultTimezone)
}
开发者ID:bhepp,项目名称:cgrates,代码行数:14,代码来源:kamevent.go
示例14: GetPdd
func (fsev FSEvent) GetPdd(fieldName string) (time.Duration, error) {
var pddStr string
if utils.IsSliceMember([]string{utils.PDD, utils.META_DEFAULT}, fieldName) {
pddStr = utils.FirstNonEmpty(fsev[PDD_MEDIA_MS], fsev[PDD_NOMEDIA_MS])
if len(pddStr) != 0 {
pddStr = pddStr + "ms" // PDD is in milliseconds and CGR expects it in seconds
}
} else if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
pddStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
} else {
pddStr = fsev[fieldName]
}
return utils.ParseDurationWithSecs(pddStr)
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:14,代码来源:fsevent.go
示例15: AsCallDescriptor
// Converts into CallDescriptor due to responder interface needs
func (fsev FSEvent) AsCallDescriptor() (*engine.CallDescriptor, error) {
lcrReq := &engine.LcrRequest{
Direction: fsev.GetDirection(utils.META_DEFAULT),
Tenant: fsev.GetTenant(utils.META_DEFAULT),
Category: fsev.GetCategory(utils.META_DEFAULT),
Account: fsev.GetAccount(utils.META_DEFAULT),
Subject: fsev.GetSubject(utils.META_DEFAULT),
Destination: fsev.GetDestination(utils.META_DEFAULT),
SetupTime: utils.FirstNonEmpty(fsev[SETUP_TIME], fsev[ANSWER_TIME]),
Duration: fsev[DURATION],
ExtraFields: fsev.GetExtraFields(),
}
return lcrReq.AsCallDescriptor(config.CgrConfig().DefaultTimezone)
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:15,代码来源:fsevent.go
示例16: AsLcrRequest
func (self SMGenericEvent) AsLcrRequest() *engine.LcrRequest {
setupTimeStr, _ := utils.ConvertIfaceToString(self[utils.SETUP_TIME])
usageStr, _ := utils.ConvertIfaceToString(self[utils.USAGE])
return &engine.LcrRequest{
Direction: self.GetDirection(utils.META_DEFAULT),
Tenant: self.GetTenant(utils.META_DEFAULT),
Category: self.GetCategory(utils.META_DEFAULT),
Account: self.GetAccount(utils.META_DEFAULT),
Subject: self.GetSubject(utils.META_DEFAULT),
Destination: self.GetDestination(utils.META_DEFAULT),
SetupTime: utils.FirstNonEmpty(setupTimeStr),
Duration: usageStr,
}
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:14,代码来源:smg_event.go
示例17: AsStoredCdr
func (self SMGenericEvent) AsStoredCdr(cfg *config.CGRConfig, timezone string) *engine.CDR {
storCdr := engine.NewCDRWithDefaults(cfg)
storCdr.CGRID = self.GetCgrId(timezone)
storCdr.ToR = utils.FirstNonEmpty(self.GetTOR(utils.META_DEFAULT), storCdr.ToR) // Keep default if none in the event
storCdr.OriginID = self.GetUUID()
storCdr.OriginHost = self.GetOriginatorIP(utils.META_DEFAULT)
storCdr.Source = self.GetCdrSource()
storCdr.RequestType = utils.FirstNonEmpty(self.GetReqType(utils.META_DEFAULT), storCdr.RequestType)
storCdr.Direction = utils.FirstNonEmpty(self.GetDirection(utils.META_DEFAULT), storCdr.Direction)
storCdr.Tenant = utils.FirstNonEmpty(self.GetTenant(utils.META_DEFAULT), storCdr.Tenant)
storCdr.Category = utils.FirstNonEmpty(self.GetCategory(utils.META_DEFAULT), storCdr.Category)
storCdr.Account = self.GetAccount(utils.META_DEFAULT)
storCdr.Subject = self.GetSubject(utils.META_DEFAULT)
storCdr.Destination = self.GetDestination(utils.META_DEFAULT)
storCdr.SetupTime, _ = self.GetSetupTime(utils.META_DEFAULT, timezone)
storCdr.AnswerTime, _ = self.GetAnswerTime(utils.META_DEFAULT, timezone)
storCdr.Usage, _ = self.GetUsage(utils.META_DEFAULT)
storCdr.PDD, _ = self.GetPdd(utils.META_DEFAULT)
storCdr.Supplier = self.GetSupplier(utils.META_DEFAULT)
storCdr.DisconnectCause = self.GetDisconnectCause(utils.META_DEFAULT)
storCdr.ExtraFields = self.GetExtraFields()
storCdr.Cost = -1
return storCdr
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:24,代码来源:smg_event.go
示例18: AsStoredCdr
func (fsCdr FSCdr) AsStoredCdr() *utils.StoredCdr {
storCdr := new(utils.StoredCdr)
storCdr.CgrId = fsCdr.getCgrId()
storCdr.TOR = utils.VOICE
storCdr.AccId = fsCdr.vars[FS_UUID]
storCdr.CdrHost = fsCdr.vars[FS_IP]
storCdr.CdrSource = FS_CDR_SOURCE
storCdr.ReqType = utils.FirstNonEmpty(fsCdr.vars[FS_REQTYPE], cfg.DefaultReqType)
storCdr.Direction = "*out"
storCdr.Tenant = utils.FirstNonEmpty(fsCdr.vars[FS_CSTMID], cfg.DefaultTenant)
storCdr.Category = utils.FirstNonEmpty(fsCdr.vars[FS_CATEGORY], cfg.DefaultCategory)
storCdr.Account = utils.FirstNonEmpty(fsCdr.vars[FS_ACCOUNT], fsCdr.vars[FS_USERNAME])
storCdr.Subject = utils.FirstNonEmpty(fsCdr.vars[FS_SUBJECT], fsCdr.vars[FS_USERNAME])
storCdr.Destination = utils.FirstNonEmpty(fsCdr.vars[FS_DESTINATION], fsCdr.vars[FS_CALL_DEST_NR], fsCdr.vars[FS_SIP_REQUSER])
storCdr.SetupTime, _ = utils.ParseTimeDetectLayout(fsCdr.vars[FS_SETUP_TIME]) // Not interested to process errors, should do them if necessary in a previous step
storCdr.AnswerTime, _ = utils.ParseTimeDetectLayout(fsCdr.vars[FS_ANSWER_TIME])
storCdr.Usage, _ = utils.ParseDurationWithSecs(fsCdr.vars[FS_DURATION])
storCdr.ExtraFields = fsCdr.getExtraFields()
storCdr.Cost = -1
return storCdr
}
开发者ID:intralanman,项目名称:cgrates,代码行数:21,代码来源:fscdr.go
示例19: NewCdrc
/*
One instance of CDRC will act on one folder.
Common parameters within configs processed:
* cdrS, cdrFormat, cdrInDir, cdrOutDir, runDelay
Parameters specific per config instance:
* duMultiplyFactor, cdrSourceId, cdrFilter, cdrFields
*/
func NewCdrc(cdrcCfgs map[string]*config.CdrcConfig, httpSkipTlsCheck bool, cdrs engine.Connector, closeChan chan struct{}, dfltTimezone string) (*Cdrc, error) {
var cdrcCfg *config.CdrcConfig
for _, cdrcCfg = range cdrcCfgs { // Take the first config out, does not matter which one
break
}
cdrc := &Cdrc{httpSkipTlsCheck: httpSkipTlsCheck, cdrcCfgs: cdrcCfgs, dfltCdrcCfg: cdrcCfg, timezone: utils.FirstNonEmpty(cdrcCfg.Timezone, dfltTimezone), cdrs: cdrs,
closeChan: closeChan, maxOpenFiles: make(chan struct{}, cdrcCfg.MaxOpenFiles),
}
var processFile struct{}
for i := 0; i < cdrcCfg.MaxOpenFiles; i++ {
cdrc.maxOpenFiles <- processFile // Empty initiate so we do not need to wait later when we pop
}
var err error
if cdrc.partialRecordsCache, err = NewPartialRecordsCache(cdrcCfg.PartialRecordCache, cdrcCfg.CdrOutDir, cdrcCfg.FieldSeparator); err != nil {
return nil, err
}
// Before processing, make sure in and out folders exist
for _, dir := range []string{cdrcCfg.CdrInDir, cdrcCfg.CdrOutDir} {
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
return nil, fmt.Errorf("Nonexistent folder: %s", dir)
}
}
cdrc.httpClient = new(http.Client)
return cdrc, nil
}
开发者ID:bhepp,项目名称:cgrates,代码行数:32,代码来源:cdrc.go
示例20: GetDisconnectCause
func (osipsev *OsipsEvent) GetDisconnectCause(fieldName string) string {
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
}
return utils.FirstNonEmpty(osipsev.osipsEvent.AttrValues[fieldName], osipsev.osipsEvent.AttrValues[OSIPS_SIPCODE], osipsev.osipsEvent.AttrValues[utils.DISCONNECT_CAUSE])
}
开发者ID:iwada,项目名称:cgrates,代码行数:6,代码来源:osipsevent.go
注:本文中的github.com/cgrates/cgrates/utils.FirstNonEmpty函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论