本文整理匯總了Golang中github.com/cgrates/cgrates/utils.RSRField.IsStatic方法的典型用法代碼示例。如果您正苦於以下問題:Golang RSRField.IsStatic方法的具體用法?Golang RSRField.IsStatic怎麽用?Golang RSRField.IsStatic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cgrates/cgrates/utils.RSRField
的用法示例。
在下文中一共展示了RSRField.IsStatic方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FieldAsString
// Used to retrieve fields as string, primary fields are const labeled
func (storedCdr *StoredCdr) FieldAsString(rsrFld *utils.RSRField) string {
if rsrFld.IsStatic() { // Static values do not care about headers
return rsrFld.ParseValue("")
}
switch rsrFld.Id {
case utils.CGRID:
return rsrFld.ParseValue(storedCdr.CgrId)
case utils.ORDERID:
return rsrFld.ParseValue(strconv.FormatInt(storedCdr.OrderId, 10))
case utils.TOR:
return rsrFld.ParseValue(storedCdr.TOR)
case utils.ACCID:
return rsrFld.ParseValue(storedCdr.AccId)
case utils.CDRHOST:
return rsrFld.ParseValue(storedCdr.CdrHost)
case utils.CDRSOURCE:
return rsrFld.ParseValue(storedCdr.CdrSource)
case utils.REQTYPE:
return rsrFld.ParseValue(storedCdr.ReqType)
case utils.DIRECTION:
return rsrFld.ParseValue(storedCdr.Direction)
case utils.TENANT:
return rsrFld.ParseValue(storedCdr.Tenant)
case utils.CATEGORY:
return rsrFld.ParseValue(storedCdr.Category)
case utils.ACCOUNT:
return rsrFld.ParseValue(storedCdr.Account)
case utils.SUBJECT:
return rsrFld.ParseValue(storedCdr.Subject)
case utils.DESTINATION:
return rsrFld.ParseValue(storedCdr.Destination)
case utils.SETUP_TIME:
return rsrFld.ParseValue(storedCdr.SetupTime.Format(time.RFC3339))
case utils.PDD:
return strconv.FormatFloat(storedCdr.Pdd.Seconds(), 'f', -1, 64)
case utils.ANSWER_TIME:
return rsrFld.ParseValue(storedCdr.AnswerTime.Format(time.RFC3339))
case utils.USAGE:
return strconv.FormatFloat(storedCdr.Usage.Seconds(), 'f', -1, 64)
case utils.SUPPLIER:
return rsrFld.ParseValue(storedCdr.Supplier)
case utils.DISCONNECT_CAUSE:
return rsrFld.ParseValue(storedCdr.DisconnectCause)
case utils.MEDI_RUNID:
return rsrFld.ParseValue(storedCdr.MediationRunId)
case utils.RATED_ACCOUNT:
return rsrFld.ParseValue(storedCdr.RatedAccount)
case utils.RATED_SUBJECT:
return rsrFld.ParseValue(storedCdr.RatedSubject)
case utils.RATED_FLD:
return rsrFld.ParseValue(strconv.FormatBool(storedCdr.Rated))
case utils.COST:
return rsrFld.ParseValue(strconv.FormatFloat(storedCdr.Cost, 'f', -1, 64)) // Recommended to use FormatCost
case utils.COST_DETAILS:
return rsrFld.ParseValue(storedCdr.CostDetailsJson())
default:
return rsrFld.ParseValue(storedCdr.ExtraFields[rsrFld.Id])
}
}
示例2: PassesFieldFilter
func (storedCdr *StoredCdr) PassesFieldFilter(fieldFilter *utils.RSRField) (bool, string) {
if fieldFilter == nil {
return true, ""
}
if fieldFilter.IsStatic() && storedCdr.FieldAsString(&utils.RSRField{Id: fieldFilter.Id}) == storedCdr.FieldAsString(fieldFilter) {
return true, storedCdr.FieldAsString(&utils.RSRField{Id: fieldFilter.Id})
}
preparedFilter := &utils.RSRField{Id: fieldFilter.Id, RSRules: make([]*utils.ReSearchReplace, len(fieldFilter.RSRules))} // Reset rules so they do not point towards same structures as original fieldFilter
for idx := range fieldFilter.RSRules {
// Hardcode the template with maximum of 5 groups ordered
preparedFilter.RSRules[idx] = &utils.ReSearchReplace{SearchRegexp: fieldFilter.RSRules[idx].SearchRegexp, ReplaceTemplate: utils.FILTER_REGEXP_TPL}
}
preparedVal := storedCdr.FieldAsString(preparedFilter)
filteredValue := storedCdr.FieldAsString(fieldFilter)
if preparedFilter.RegexpMatched() && (len(preparedVal) == 0 || preparedVal == filteredValue) {
return true, filteredValue
}
return false, ""
}
示例3: PassesFieldFilter
func (fsev FSEvent) PassesFieldFilter(fieldFilter *utils.RSRField) (bool, string) {
// Keep in sync (or merge) with StoredCdr.PassesFieldFielter()
if fieldFilter == nil {
return true, ""
}
if fieldFilter.IsStatic() && fsev.ParseEventValue(&utils.RSRField{Id: fieldFilter.Id}, config.CgrConfig().DefaultTimezone) == fsev.ParseEventValue(fieldFilter, config.CgrConfig().DefaultTimezone) {
return true, fsev.ParseEventValue(&utils.RSRField{Id: fieldFilter.Id}, config.CgrConfig().DefaultTimezone)
}
preparedFilter := &utils.RSRField{Id: fieldFilter.Id, RSRules: make([]*utils.ReSearchReplace, len(fieldFilter.RSRules))} // Reset rules so they do not point towards same structures as original fieldFilter
for idx := range fieldFilter.RSRules {
// Hardcode the template with maximum of 5 groups ordered
preparedFilter.RSRules[idx] = &utils.ReSearchReplace{SearchRegexp: fieldFilter.RSRules[idx].SearchRegexp, ReplaceTemplate: utils.FILTER_REGEXP_TPL}
}
preparedVal := fsev.ParseEventValue(preparedFilter, config.CgrConfig().DefaultTimezone)
filteredValue := fsev.ParseEventValue(fieldFilter, config.CgrConfig().DefaultTimezone)
if preparedFilter.RegexpMatched() && (len(preparedVal) == 0 || preparedVal == filteredValue) {
return true, filteredValue
}
return false, ""
}