mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Changed consts in utils
This commit is contained in:
committed by
Dan Christian Bogos
parent
8bcbd789e6
commit
4883754cf0
@@ -98,24 +98,24 @@ func (fsev FSEvent) GetName() string {
|
||||
|
||||
// Account calling
|
||||
func (fsev FSEvent) GetAccount(fieldName string) string {
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
return fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.FirstNonEmpty(fsev[fieldName], fsev[ACCOUNT], fsev[USERNAME])
|
||||
}
|
||||
|
||||
// Rating subject being charged
|
||||
func (fsev FSEvent) GetSubject(fieldName string) string {
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
return fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.FirstNonEmpty(fsev[fieldName], fsev[SUBJECT], fsev.GetAccount(fieldName))
|
||||
}
|
||||
|
||||
// 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):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
return fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.FirstNonEmpty(fsev[fieldName], fsev[DESTINATION],
|
||||
fsev[CALL_DEST_NR], fsev[SIP_REQ_USER])
|
||||
@@ -123,14 +123,14 @@ func (fsev FSEvent) GetDestination(fieldName string) string {
|
||||
|
||||
// Original dialed destination number, useful in case of unpark
|
||||
func (fsev FSEvent) GetCallDestNr(fieldName string) string {
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
return fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.FirstNonEmpty(fsev[fieldName], fsev[CALL_DEST_NR], fsev[SIP_REQ_USER])
|
||||
}
|
||||
func (fsev FSEvent) GetCategory(fieldName string) string {
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
return fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.FirstNonEmpty(fsev[fieldName], fsev[CATEGORY],
|
||||
config.CgrConfig().GeneralCfg().DefaultCategory)
|
||||
@@ -145,8 +145,8 @@ func (fsev FSEvent) GetSessionIds() []string {
|
||||
}
|
||||
|
||||
func (fsev FSEvent) GetTenant(fieldName string) string {
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
return fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.FirstNonEmpty(fsev[fieldName], fsev[CSTMID],
|
||||
config.CgrConfig().GeneralCfg().DefaultTenant)
|
||||
@@ -159,8 +159,8 @@ func (fsev FSEvent) GetReqType(fieldName string) string {
|
||||
} 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):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
return fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.FirstNonEmpty(fsev[fieldName], fsev[REQTYPE],
|
||||
reqTypeDetected, config.CgrConfig().GeneralCfg().DefaultReqType)
|
||||
@@ -198,8 +198,8 @@ func (fsev FSEvent) GetSetupTime(fieldName, timezone string) (t time.Time, err e
|
||||
fsSTimeStr = fsSTimeStr[:len(fsSTimeStr)-6]
|
||||
}
|
||||
sTimeStr := utils.FirstNonEmpty(fsev[fieldName], fsSTimeStr)
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
sTimeStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
sTimeStr = fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.ParseTimeDetectLayout(sTimeStr, timezone)
|
||||
}
|
||||
@@ -211,8 +211,8 @@ func (fsev FSEvent) GetAnswerTime(fieldName, timezone string) (t time.Time, err
|
||||
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):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
aTimeStr = fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.ParseTimeDetectLayout(aTimeStr, timezone)
|
||||
}
|
||||
@@ -223,8 +223,8 @@ func (fsev FSEvent) GetEndTime(fieldName, timezone string) (t time.Time, err err
|
||||
|
||||
func (fsev FSEvent) GetDuration(fieldName string) (time.Duration, error) {
|
||||
durStr := utils.FirstNonEmpty(fsev[fieldName], fsev[DURATION])
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
durStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
durStr = fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.ParseDurationWithSecs(durStr)
|
||||
}
|
||||
@@ -236,8 +236,8 @@ func (fsev FSEvent) GetPdd(fieldName string) (time.Duration, error) {
|
||||
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 if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
PDDStr = fieldName[len(utils.StaticValuePrefix):]
|
||||
} else {
|
||||
PDDStr = fsev[fieldName]
|
||||
}
|
||||
@@ -251,8 +251,8 @@ func (fsev FSEvent) GetADC(fieldName string) (time.Duration, error) {
|
||||
if len(ACDStr) != 0 {
|
||||
ACDStr = ACDStr + "s" // ACD is in seconds and CGR expects it in seconds
|
||||
}
|
||||
} else if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
ACDStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
} else if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
ACDStr = fieldName[len(utils.StaticValuePrefix):]
|
||||
} else {
|
||||
ACDStr = fsev[fieldName]
|
||||
}
|
||||
@@ -260,22 +260,22 @@ func (fsev FSEvent) GetADC(fieldName string) (time.Duration, error) {
|
||||
}
|
||||
|
||||
func (fsev FSEvent) GetRoute(fieldName string) string {
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
return fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.FirstNonEmpty(fsev[fieldName], fsev[VAR_CGR_ROUTE])
|
||||
}
|
||||
|
||||
func (fsev FSEvent) GetDisconnectCause(fieldName string) string {
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
return fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.FirstNonEmpty(fsev[fieldName], fsev[VAR_CGR_DISCONNECT_CAUSE], fsev[HANGUP_CAUSE])
|
||||
}
|
||||
|
||||
func (fsev FSEvent) GetOriginatorIP(fieldName string) string {
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
return fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
if strings.HasPrefix(fieldName, utils.StaticValuePrefix) { // Static value
|
||||
return fieldName[len(utils.StaticValuePrefix):]
|
||||
}
|
||||
return utils.FirstNonEmpty(fsev[fieldName], fsev[VarCGROriginHost], fsev[FS_IPv4])
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func (apiv2 *APIerSv2) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolde
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if attrs.DryRun {
|
||||
*reply = utils.LoadInstance{RatingLoadID: utils.DRYRUN, AccountingLoadID: utils.DRYRUN}
|
||||
*reply = utils.LoadInstance{RatingLoadID: utils.DryRunCfg, AccountingLoadID: utils.DryRunCfg}
|
||||
return nil // Mission complete, no errors
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ func HTTPPostJSON(url string, content []byte) (respBody []byte, err error) {
|
||||
// NewHTTPPoster return a new HTTP poster
|
||||
func NewHTTPPoster(replyTimeout time.Duration, addr, contentType string,
|
||||
attempts int) (httposter *HTTPPoster, err error) {
|
||||
if !utils.SliceHasMember([]string{utils.CONTENT_FORM, utils.ContentJSON, utils.CONTENT_TEXT}, contentType) {
|
||||
if !utils.SliceHasMember([]string{utils.ContentForm, utils.ContentJSON, utils.ContentText}, contentType) {
|
||||
return nil, fmt.Errorf("unsupported ContentType: %s", contentType)
|
||||
}
|
||||
return &HTTPPoster{
|
||||
@@ -124,7 +124,7 @@ func (pstr *HTTPPoster) do(req *http.Request) (respBody []byte, err error) {
|
||||
|
||||
func (pstr *HTTPPoster) getRequest(content interface{}, hdr http.Header) (req *http.Request, err error) {
|
||||
var body io.Reader
|
||||
if pstr.contentType == utils.CONTENT_FORM {
|
||||
if pstr.contentType == utils.ContentForm {
|
||||
body = strings.NewReader(content.(url.Values).Encode())
|
||||
} else {
|
||||
body = bytes.NewBuffer(content.([]byte))
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestHttpBytesPoster(t *testing.T) {
|
||||
content := []byte(`Test
|
||||
Test2
|
||||
`)
|
||||
pstr, err := NewHTTPPoster(2*time.Second, "http://localhost:8080/invalid", utils.CONTENT_TEXT, 3)
|
||||
pstr, err := NewHTTPPoster(2*time.Second, "http://localhost:8080/invalid", utils.ContentText, 3)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func fieldinfo2Attribute(attr []*engine.Attribute, fieldName, fieldInfo string)
|
||||
if fieldInfo == utils.MetaDefault || len(fieldInfo) == 0 {
|
||||
return attr
|
||||
}
|
||||
if strings.HasPrefix(fieldInfo, utils.STATIC_VALUE_PREFIX) {
|
||||
if strings.HasPrefix(fieldInfo, utils.StaticValuePrefix) {
|
||||
fieldInfo = fieldInfo[1:]
|
||||
}
|
||||
var err error
|
||||
@@ -136,7 +136,7 @@ func derivedChargers2Charger(dc *v1DerivedCharger, tenant string, key string, fi
|
||||
|
||||
filter := dc.RunFilters
|
||||
if len(filter) != 0 {
|
||||
if strings.HasPrefix(filter, utils.STATIC_VALUE_PREFIX) {
|
||||
if strings.HasPrefix(filter, utils.StaticValuePrefix) {
|
||||
filter = filter[1:]
|
||||
}
|
||||
if strings.HasPrefix(filter, utils.DynamicDataPrefix) {
|
||||
|
||||
@@ -33,7 +33,7 @@ var (
|
||||
MetaHTTPjsonCDR: ContentJSON,
|
||||
MetaHTTPjsonMap: ContentJSON,
|
||||
MetaHTTPjson: ContentJSON,
|
||||
MetaHTTPPost: CONTENT_FORM,
|
||||
MetaHTTPPost: ContentForm,
|
||||
MetaAMQPjsonCDR: ContentJSON,
|
||||
MetaAMQPjsonMap: ContentJSON,
|
||||
MetaAMQPV1jsonMap: ContentJSON,
|
||||
@@ -340,11 +340,10 @@ const (
|
||||
RATED = "rated"
|
||||
Partial = "Partial"
|
||||
PreRated = "PreRated"
|
||||
STATIC_VALUE_PREFIX = "^"
|
||||
StaticValuePrefix = "^"
|
||||
CSV = "csv"
|
||||
FWV = "fwv"
|
||||
MetaPartialCSV = "*partial_csv"
|
||||
DRYRUN = "dry_run"
|
||||
META_COMBIMED = "*combimed"
|
||||
MetaMongo = "*mongo"
|
||||
MetaPostgres = "*postgres"
|
||||
@@ -525,8 +524,8 @@ const (
|
||||
CSVSuffix = ".csv"
|
||||
FWVSuffix = ".fwv"
|
||||
ContentJSON = "json"
|
||||
CONTENT_FORM = "form"
|
||||
CONTENT_TEXT = "text"
|
||||
ContentForm = "form"
|
||||
ContentText = "text"
|
||||
FileLockPrefix = "file_"
|
||||
ActionsPoster = "act"
|
||||
CDRPoster = "cdr"
|
||||
|
||||
Reference in New Issue
Block a user