mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added methods for MapEvent and SafEvent to implement config.DataProvider
This commit is contained in:
committed by
Dan Christian Bogos
parent
98ddf46256
commit
b8d4b1de73
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
@@ -41,6 +42,32 @@ func (me MapEvent) String() string {
|
||||
return utils.ToJSON(me)
|
||||
}
|
||||
|
||||
func (me MapEvent) FieldAsInterface(fldPath []string) (interface{}, error) {
|
||||
if len(fldPath) != 1 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
fldIface, has := me[fldPath[0]]
|
||||
if !has {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return fldIface, nil
|
||||
}
|
||||
|
||||
func (me MapEvent) FieldAsString(fldPath []string) (string, error) {
|
||||
if len(fldPath) != 1 {
|
||||
return "", utils.ErrNotFound
|
||||
}
|
||||
return me.GetString(fldPath[0])
|
||||
}
|
||||
|
||||
func (me MapEvent) AsNavigableMap([]*config.FCTemplate) (*config.NavigableMap, error) {
|
||||
return config.NewNavigableMap(me), nil
|
||||
}
|
||||
|
||||
func (me MapEvent) RemoteHost() net.Addr {
|
||||
return new(utils.LocalAddr)
|
||||
}
|
||||
|
||||
func (me MapEvent) HasField(fldName string) (has bool) {
|
||||
_, has = me[fldName]
|
||||
return
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -55,6 +56,34 @@ func (se *SafEvent) String() (out string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (se *SafEvent) FieldAsInterface(fldPath []string) (out interface{}, err error) {
|
||||
se.RLock()
|
||||
out, err = se.Me.FieldAsInterface(fldPath)
|
||||
se.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (se *SafEvent) FieldAsString(fldPath []string) (out string, err error) {
|
||||
se.RLock()
|
||||
out, err = se.Me.FieldAsString(fldPath)
|
||||
se.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (se *SafEvent) AsNavigableMap(fctemplate []*config.FCTemplate) (out *config.NavigableMap, err error) {
|
||||
se.RLock()
|
||||
out, err = se.Me.AsNavigableMap(fctemplate)
|
||||
se.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (se *SafEvent) RemoteHost() (out net.Addr) {
|
||||
se.RLock()
|
||||
out = se.Me.RemoteHost()
|
||||
se.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (se *SafEvent) HasField(fldName string) (has bool) {
|
||||
se.RLock()
|
||||
has = se.Me.HasField(fldName)
|
||||
|
||||
Reference in New Issue
Block a user