mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
Add functions for getting interface type values from config/APIOpts
This commit is contained in:
committed by
Dan Christian Bogos
parent
d43fc7a27a
commit
02315c7ad0
@@ -165,3 +165,23 @@ func FilterDecimalBigCfgOpts(ctx *context.Context, tnt string, ev utils.DataProv
|
||||
}
|
||||
return // return the option or NOT_FOUND if there are no options or none of the filters pass
|
||||
}
|
||||
|
||||
// FilterInterfaceCfgOpts returns the option as interface{} if the filters match
|
||||
func FilterInterfaceCfgOpts(ctx *context.Context, tnt string, ev utils.DataProvider, fS *FilterS, dynOpts []*utils.DynamicInterfaceOpt) (dft interface{}, err error) {
|
||||
var hasDefault bool
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if len(opt.FilterIDs) == 0 {
|
||||
hasDefault = true
|
||||
dft = opt.Value
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, ev); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
return false, err
|
||||
} else if pass {
|
||||
return opt.Value, nil
|
||||
}
|
||||
}
|
||||
if !hasDefault {
|
||||
err = utils.ErrNotFound
|
||||
}
|
||||
return // return the option or NOT_FOUND if there are no options or none of the filters pass
|
||||
}
|
||||
|
||||
@@ -150,6 +150,16 @@ func (ev *CGREvent) OptsAsStringSlice(defaultValue []string, optNames ...string)
|
||||
return defaultValue, nil
|
||||
}
|
||||
|
||||
// OptsAsInterface returns an option as float64
|
||||
func (ev *CGREvent) OptsAsInterface(defaultValue interface{}, optNames ...string) interface{} {
|
||||
for _, optName := range optNames {
|
||||
if iface, has := ev.APIOpts[optName]; has {
|
||||
return iface
|
||||
}
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func (ev *CGREvent) Clone() (clned *CGREvent) {
|
||||
clned = &CGREvent{
|
||||
Tenant: ev.Tenant,
|
||||
|
||||
Reference in New Issue
Block a user