Added FieldAsInterface for EventCost

This commit is contained in:
Trial97
2020-02-05 11:02:55 +02:00
committed by Dan Christian Bogos
parent 2f8b7dc53e
commit ff5f5f2d21
7 changed files with 532 additions and 121 deletions

View File

@@ -233,6 +233,25 @@ type Rate struct {
RateUnit time.Duration
}
// FieldAsInterface func to help EventCost FieldAsInterface
func (r *Rate) FieldAsInterface(fldPath []string) (val interface{}, err error) {
if len(fldPath) != 1 {
return nil, utils.ErrNotFound
}
switch fldPath[0] {
default:
return nil, fmt.Errorf("unsupported field prefix: <%s>", fldPath[0])
case utils.GroupIntervalStart:
return r.GroupIntervalStart, nil
case utils.Value:
return r.Value, nil
case utils.RateIncrement:
return r.RateIncrement, nil
case utils.RateUnit:
return r.RateUnit, nil
}
}
func (r *Rate) Stringify() string {
return utils.Sha1(fmt.Sprintf("%v", r))[:8]
}