mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 16:48:45 +05:00
Updated RPCParams map locking
This commit is contained in:
committed by
Dan Christian Bogos
parent
51f27b0396
commit
231adb1284
@@ -18,9 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package utils
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"reflect"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var rpcParamsMap map[string]*RpcParams
|
||||
var (
|
||||
rpcParamsMap = make(map[string]*RpcParams)
|
||||
rpcParamsLock sync.RWMutex
|
||||
)
|
||||
|
||||
type RpcParams struct {
|
||||
Object interface{}
|
||||
@@ -28,10 +34,6 @@ type RpcParams struct {
|
||||
OutParam interface{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rpcParamsMap = make(map[string]*RpcParams)
|
||||
}
|
||||
|
||||
func RegisterRpcParams(name string, obj interface{}) {
|
||||
objType := reflect.TypeOf(obj)
|
||||
if name == "" {
|
||||
@@ -49,17 +51,21 @@ func RegisterRpcParams(name string, obj interface{}) {
|
||||
if out.Kind() == reflect.Ptr {
|
||||
out = out.Elem()
|
||||
}
|
||||
rpcParamsLock.Lock()
|
||||
rpcParamsMap[name+"."+method.Name] = &RpcParams{
|
||||
Object: obj,
|
||||
InParam: reflect.New(methodType.In(1)).Interface(),
|
||||
OutParam: reflect.New(out).Interface(),
|
||||
}
|
||||
rpcParamsLock.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetRpcParams(method string) (*RpcParams, error) {
|
||||
rpcParamsLock.Lock()
|
||||
x, found := rpcParamsMap[method]
|
||||
rpcParamsLock.Unlock()
|
||||
if !found {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user