mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Replace interface{} with any
This commit is contained in:
committed by
Dan Christian Bogos
parent
97c3dab0f4
commit
6c16ff320f
@@ -126,7 +126,7 @@ func (aS *AnalyzerService) Shutdown() error {
|
||||
}
|
||||
|
||||
func (aS *AnalyzerService) logTrafic(id uint64, method string,
|
||||
params, result, err interface{},
|
||||
params, result, err any,
|
||||
enc, from, to string, sTime, eTime time.Time) error {
|
||||
if strings.HasPrefix(method, utils.AnalyzerSv1) {
|
||||
return nil
|
||||
@@ -144,7 +144,7 @@ type QueryArgs struct {
|
||||
}
|
||||
|
||||
// V1StringQuery returns a list of API that match the query
|
||||
func (aS *AnalyzerService) V1StringQuery(args *QueryArgs, reply *[]map[string]interface{}) error {
|
||||
func (aS *AnalyzerService) V1StringQuery(args *QueryArgs, reply *[]map[string]any) error {
|
||||
var q query.Query
|
||||
if args.HeaderFilters == utils.EmptyString {
|
||||
q = bleve.NewMatchAllQuery()
|
||||
@@ -157,7 +157,7 @@ func (aS *AnalyzerService) V1StringQuery(args *QueryArgs, reply *[]map[string]in
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rply := make([]map[string]interface{}, 0, searchResults.Hits.Len())
|
||||
rply := make([]map[string]any, 0, searchResults.Hits.Len())
|
||||
lenContentFltrs := len(args.ContentFilters)
|
||||
for _, obj := range searchResults.Hits {
|
||||
// make sure that the result is corectly marshaled
|
||||
|
||||
@@ -135,7 +135,7 @@ func testAnalyzerSRPCConn(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
anzBiRPC = rpc2.NewClientWithCodec(jsonrpc2.NewJSONCodec(conn))
|
||||
anzBiRPC.Handle(utils.SessionSv1DisconnectPeer, func(clnt *rpc2.Client, args interface{}, rply *string) (err error) { return utils.ErrNotFound })
|
||||
anzBiRPC.Handle(utils.SessionSv1DisconnectPeer, func(clnt *rpc2.Client, args any, rply *string) (err error) { return utils.ErrNotFound })
|
||||
go anzBiRPC.Run()
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ func testAnalyzerSChargerSv1ProcessEvent(t *testing.T) {
|
||||
cgrEv := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
Event: map[string]any{
|
||||
utils.AccountField: "1010",
|
||||
utils.Subject: "Something_inter",
|
||||
utils.Destination: "999",
|
||||
@@ -169,13 +169,13 @@ func testAnalyzerSChargerSv1ProcessEvent(t *testing.T) {
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
Event: map[string]any{
|
||||
"Account": "1010",
|
||||
"Destination": "999",
|
||||
"RunID": "*default",
|
||||
"Subject": "Something_inter",
|
||||
},
|
||||
APIOpts: map[string]interface{}{"*subsys": "*chargers"},
|
||||
APIOpts: map[string]any{"*subsys": "*chargers"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -185,16 +185,16 @@ func testAnalyzerSChargerSv1ProcessEvent(t *testing.T) {
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
Event: map[string]any{
|
||||
"Account": "1010",
|
||||
"Destination": "999",
|
||||
"RequestType": "*none",
|
||||
"RunID": "*raw",
|
||||
"Subject": "Something_inter",
|
||||
},
|
||||
APIOpts: map[string]interface{}{
|
||||
APIOpts: map[string]any{
|
||||
"*subsys": "*chargers",
|
||||
utils.OptsAttributesProfileIDs: []interface{}{"*constant:*req.RequestType:*none"},
|
||||
utils.OptsAttributesProfileIDs: []any{"*constant:*req.RequestType:*none"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -215,7 +215,7 @@ func testAnalyzerSChargerSv1ProcessEvent(t *testing.T) {
|
||||
func testAnalyzerSV1Search(t *testing.T) {
|
||||
// need to wait in order for the log gorutine to execute
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
var result []map[string]interface{}
|
||||
var result []map[string]any
|
||||
if err := anzRPC.Call(utils.AnalyzerSv1StringQuery, &QueryArgs{HeaderFilters: `+RequestEncoding:\*internal +RequestMethod:AttributeSv1\.ProcessEvent`}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(result) != 1 {
|
||||
@@ -224,7 +224,7 @@ func testAnalyzerSV1Search(t *testing.T) {
|
||||
}
|
||||
|
||||
func testAnalyzerSV1Search2(t *testing.T) {
|
||||
var result []map[string]interface{}
|
||||
var result []map[string]any
|
||||
if err := anzRPC.Call(utils.AnalyzerSv1StringQuery, &QueryArgs{HeaderFilters: `+RequestEncoding:\*json +RequestMethod:ChargerSv1\.ProcessEvent`}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(result) != 1 {
|
||||
@@ -233,7 +233,7 @@ func testAnalyzerSV1Search2(t *testing.T) {
|
||||
}
|
||||
|
||||
func testAnalyzerSV1SearchWithContentFilters(t *testing.T) {
|
||||
var result []map[string]interface{}
|
||||
var result []map[string]any
|
||||
if err := anzRPC.Call(utils.AnalyzerSv1StringQuery, &QueryArgs{
|
||||
HeaderFilters: `+RequestEncoding:\*json`,
|
||||
ContentFilters: []string{"*string:~*req.Event.Account:1010"},
|
||||
@@ -253,7 +253,7 @@ func testAnalyzerSV1BirPCSession(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
time.Sleep(10 * time.Second)
|
||||
var result []map[string]interface{}
|
||||
var result []map[string]any
|
||||
if err := anzRPC.Call(utils.AnalyzerSv1StringQuery, &QueryArgs{HeaderFilters: `+RequestEncoding:\*birpc_json +RequestMethod:"SessionSv1.DisconnectPeer"`}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(result) != 1 {
|
||||
|
||||
@@ -200,7 +200,7 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
t1 := time.Now()
|
||||
if err = anz.logTrafic(0, utils.CoreSv1Ping,
|
||||
&utils.CGREvent{
|
||||
APIOpts: map[string]interface{}{
|
||||
APIOpts: map[string]any{
|
||||
utils.EventSource: utils.MetaCDRs,
|
||||
},
|
||||
}, utils.Pong, nil, utils.MetaJSON, "127.0.0.1:5565",
|
||||
@@ -210,7 +210,7 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
|
||||
if err = anz.logTrafic(1, utils.CoreSv1Ping,
|
||||
&utils.CGREvent{
|
||||
APIOpts: map[string]interface{}{
|
||||
APIOpts: map[string]any{
|
||||
utils.EventSource: utils.MetaAttributes,
|
||||
},
|
||||
}, utils.Pong, nil,
|
||||
@@ -222,7 +222,7 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
|
||||
if err = anz.logTrafic(2, utils.CoreSv1Ping,
|
||||
&utils.CGREvent{
|
||||
APIOpts: map[string]interface{}{
|
||||
APIOpts: map[string]any{
|
||||
utils.EventSource: utils.MetaAttributes,
|
||||
},
|
||||
}, utils.Pong, nil,
|
||||
@@ -234,7 +234,7 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
|
||||
if err = anz.logTrafic(3, utils.CoreSv1Ping,
|
||||
&utils.CGREvent{
|
||||
APIOpts: map[string]interface{}{
|
||||
APIOpts: map[string]any{
|
||||
utils.EventSource: utils.MetaAttributes,
|
||||
},
|
||||
}, utils.Pong, nil,
|
||||
@@ -245,7 +245,7 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
}
|
||||
if err = anz.logTrafic(3, utils.CoreSv1Status,
|
||||
&utils.CGREvent{
|
||||
APIOpts: map[string]interface{}{
|
||||
APIOpts: map[string]any{
|
||||
utils.EventSource: utils.MetaEEs,
|
||||
},
|
||||
}, utils.Pong, nil,
|
||||
@@ -254,20 +254,20 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
t1.Add(-11*time.Hour), t1.Add(-10*time.Hour-30*time.Minute)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reply := []map[string]interface{}{}
|
||||
reply := []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: `"` + utils.CoreSv1Ping + `"`}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(reply) != 4 {
|
||||
t.Errorf("Expected 4 hits received: %v", len(reply))
|
||||
}
|
||||
reply = []map[string]interface{}{}
|
||||
reply = []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: "RequestMethod:" + `"` + utils.CoreSv1Ping + `"`}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(reply) != 4 {
|
||||
t.Errorf("Expected 4 hits received: %v", len(reply))
|
||||
}
|
||||
|
||||
expRply := []map[string]interface{}{{
|
||||
expRply := []map[string]any{{
|
||||
"RequestDestination": "127.0.0.1:2013",
|
||||
"RequestDuration": "1h0m0s",
|
||||
"RequestEncoding": "*gob",
|
||||
@@ -279,27 +279,27 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
"RequestStartTime": t1.Add(-24 * time.Hour).UTC().Format(time.RFC3339),
|
||||
"ReplyError": nil,
|
||||
}}
|
||||
reply = []map[string]interface{}{}
|
||||
reply = []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: utils.RequestDuration + ":>=" + strconv.FormatInt(int64(time.Hour), 10)}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(expRply, reply) {
|
||||
t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply))
|
||||
}
|
||||
|
||||
reply = []map[string]interface{}{}
|
||||
reply = []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: utils.RequestStartTime + ":<=\"" + t1.Add(-23*time.Hour).UTC().Format(time.RFC3339) + "\""}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(expRply, reply) {
|
||||
t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply))
|
||||
}
|
||||
reply = []map[string]interface{}{}
|
||||
reply = []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: "RequestEncoding:*gob"}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(expRply, reply) {
|
||||
t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply))
|
||||
}
|
||||
|
||||
reply = []map[string]interface{}{}
|
||||
reply = []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{
|
||||
HeaderFilters: "RequestEncoding:*gob",
|
||||
ContentFilters: []string{"*string:~*rep:Pong"},
|
||||
@@ -308,7 +308,7 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expRply, reply) {
|
||||
t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply))
|
||||
}
|
||||
reply = []map[string]interface{}{}
|
||||
reply = []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{
|
||||
HeaderFilters: "RequestEncoding:*gob",
|
||||
ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*attributes"},
|
||||
@@ -317,7 +317,7 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expRply, reply) {
|
||||
t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply))
|
||||
}
|
||||
reply = []map[string]interface{}{}
|
||||
reply = []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{
|
||||
HeaderFilters: "RequestEncoding:*gob",
|
||||
ContentFilters: []string{"*gt:~*hdr.RequestDuration:1m"},
|
||||
@@ -326,7 +326,7 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expRply, reply) {
|
||||
t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply))
|
||||
}
|
||||
reply = []map[string]interface{}{}
|
||||
reply = []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{
|
||||
HeaderFilters: "RequestEncoding:*gob",
|
||||
ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*attributes"},
|
||||
@@ -335,7 +335,7 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expRply, reply) {
|
||||
t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply))
|
||||
}
|
||||
expRply = []map[string]interface{}{{
|
||||
expRply = []map[string]any{{
|
||||
"RequestDestination": "127.0.0.1:2013",
|
||||
"RequestDuration": "30m0s",
|
||||
"RequestEncoding": "*birpc_json",
|
||||
@@ -347,7 +347,7 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
"RequestStartTime": t1.Add(-11 * time.Hour).UTC().Format(time.RFC3339),
|
||||
"ReplyError": nil,
|
||||
}}
|
||||
reply = []map[string]interface{}{}
|
||||
reply = []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{
|
||||
ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*ees"},
|
||||
}, &reply); err != nil {
|
||||
@@ -356,8 +356,8 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply))
|
||||
}
|
||||
|
||||
expRply = []map[string]interface{}{}
|
||||
reply = []map[string]interface{}{}
|
||||
expRply = []map[string]any{}
|
||||
reply = []map[string]any{}
|
||||
if err = anz.V1StringQuery(&QueryArgs{
|
||||
HeaderFilters: "RequestEncoding:*gob",
|
||||
ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*cdrs"},
|
||||
|
||||
@@ -63,7 +63,7 @@ func (c *AnalyzerServerCodec) ReadRequestHeader(r *rpc.Request) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (c *AnalyzerServerCodec) ReadRequestBody(x interface{}) (err error) {
|
||||
func (c *AnalyzerServerCodec) ReadRequestBody(x any) (err error) {
|
||||
err = c.sc.ReadRequestBody(x)
|
||||
c.reqsLk.Lock()
|
||||
c.reqs[c.reqIdx].Params = x
|
||||
@@ -71,7 +71,7 @@ func (c *AnalyzerServerCodec) ReadRequestBody(x interface{}) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (c *AnalyzerServerCodec) WriteResponse(r *rpc.Response, x interface{}) error {
|
||||
func (c *AnalyzerServerCodec) WriteResponse(r *rpc.Response, x any) error {
|
||||
c.reqsLk.Lock()
|
||||
api := c.reqs[r.Seq]
|
||||
delete(c.reqs, r.Seq)
|
||||
@@ -134,7 +134,7 @@ func (c *AnalyzerBiRPCCodec) ReadHeader(req *rpc2.Request, resp *rpc2.Response)
|
||||
}
|
||||
|
||||
// ReadRequestBody into args argument of handler function.
|
||||
func (c *AnalyzerBiRPCCodec) ReadRequestBody(x interface{}) (err error) {
|
||||
func (c *AnalyzerBiRPCCodec) ReadRequestBody(x any) (err error) {
|
||||
err = c.sc.ReadRequestBody(x)
|
||||
c.reqsLk.Lock()
|
||||
c.reqs[c.reqIdx].Params = x
|
||||
@@ -143,7 +143,7 @@ func (c *AnalyzerBiRPCCodec) ReadRequestBody(x interface{}) (err error) {
|
||||
}
|
||||
|
||||
// ReadResponseBody into reply argument of handler function.
|
||||
func (c *AnalyzerBiRPCCodec) ReadResponseBody(x interface{}) (err error) {
|
||||
func (c *AnalyzerBiRPCCodec) ReadResponseBody(x any) (err error) {
|
||||
err = c.sc.ReadResponseBody(x)
|
||||
c.repsLk.Lock()
|
||||
api := c.reps[c.repIdx]
|
||||
@@ -154,7 +154,7 @@ func (c *AnalyzerBiRPCCodec) ReadResponseBody(x interface{}) (err error) {
|
||||
}
|
||||
|
||||
// WriteRequest must be safe for concurrent use by multiple goroutines.
|
||||
func (c *AnalyzerBiRPCCodec) WriteRequest(req *rpc2.Request, x interface{}) error {
|
||||
func (c *AnalyzerBiRPCCodec) WriteRequest(req *rpc2.Request, x any) error {
|
||||
c.repsLk.Lock()
|
||||
c.repIdx = req.Seq
|
||||
c.reps[c.repIdx] = &rpcAPI{
|
||||
@@ -167,7 +167,7 @@ func (c *AnalyzerBiRPCCodec) WriteRequest(req *rpc2.Request, x interface{}) erro
|
||||
}
|
||||
|
||||
// WriteResponse must be safe for concurrent use by multiple goroutines.
|
||||
func (c *AnalyzerBiRPCCodec) WriteResponse(r *rpc2.Response, x interface{}) error {
|
||||
func (c *AnalyzerBiRPCCodec) WriteResponse(r *rpc2.Response, x any) error {
|
||||
c.reqsLk.Lock()
|
||||
api := c.reqs[r.Seq]
|
||||
delete(c.reqs, r.Seq)
|
||||
|
||||
@@ -40,10 +40,10 @@ func (c *mockServerCodec) ReadRequestHeader(r *rpc.Request) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (c *mockServerCodec) ReadRequestBody(x interface{}) (err error) {
|
||||
func (c *mockServerCodec) ReadRequestBody(x any) (err error) {
|
||||
return
|
||||
}
|
||||
func (c *mockServerCodec) WriteResponse(r *rpc.Response, x interface{}) error {
|
||||
func (c *mockServerCodec) WriteResponse(r *rpc.Response, x any) error {
|
||||
return nil
|
||||
}
|
||||
func (c *mockServerCodec) Close() error { return nil }
|
||||
@@ -107,11 +107,11 @@ func (mockBiRPCCodec) ReadHeader(r *rpc2.Request, _ *rpc2.Response) error {
|
||||
r.Method = utils.CoreSv1Ping
|
||||
return nil
|
||||
}
|
||||
func (mockBiRPCCodec) ReadRequestBody(interface{}) error { return nil }
|
||||
func (mockBiRPCCodec) ReadResponseBody(interface{}) error { return nil }
|
||||
func (mockBiRPCCodec) WriteRequest(*rpc2.Request, interface{}) error { return nil }
|
||||
func (mockBiRPCCodec) WriteResponse(*rpc2.Response, interface{}) error { return nil }
|
||||
func (mockBiRPCCodec) Close() error { return nil }
|
||||
func (mockBiRPCCodec) ReadRequestBody(any) error { return nil }
|
||||
func (mockBiRPCCodec) ReadResponseBody(any) error { return nil }
|
||||
func (mockBiRPCCodec) WriteRequest(*rpc2.Request, any) error { return nil }
|
||||
func (mockBiRPCCodec) WriteResponse(*rpc2.Response, any) error { return nil }
|
||||
func (mockBiRPCCodec) Close() error { return nil }
|
||||
|
||||
func TestNewBiRPCCodec(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
@@ -171,11 +171,11 @@ func (mockBiRPCCodec2) ReadHeader(_ *rpc2.Request, r *rpc2.Response) error {
|
||||
r.Error = "error"
|
||||
return nil
|
||||
}
|
||||
func (mockBiRPCCodec2) ReadRequestBody(interface{}) error { return nil }
|
||||
func (mockBiRPCCodec2) ReadResponseBody(interface{}) error { return nil }
|
||||
func (mockBiRPCCodec2) WriteRequest(*rpc2.Request, interface{}) error { return nil }
|
||||
func (mockBiRPCCodec2) WriteResponse(*rpc2.Response, interface{}) error { return nil }
|
||||
func (mockBiRPCCodec2) Close() error { return nil }
|
||||
func (mockBiRPCCodec2) ReadRequestBody(any) error { return nil }
|
||||
func (mockBiRPCCodec2) ReadResponseBody(any) error { return nil }
|
||||
func (mockBiRPCCodec2) WriteRequest(*rpc2.Request, any) error { return nil }
|
||||
func (mockBiRPCCodec2) WriteResponse(*rpc2.Response, any) error { return nil }
|
||||
func (mockBiRPCCodec2) Close() error { return nil }
|
||||
|
||||
func TestNewBiRPCCodec2(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
|
||||
@@ -43,7 +43,7 @@ type AnalyzerConnector struct {
|
||||
to string
|
||||
}
|
||||
|
||||
func (c *AnalyzerConnector) Call(serviceMethod string, args, reply interface{}) (err error) {
|
||||
func (c *AnalyzerConnector) Call(serviceMethod string, args, reply any) (err error) {
|
||||
sTime := time.Now()
|
||||
err = c.conn.Call(serviceMethod, args, reply)
|
||||
go c.aS.logTrafic(0, serviceMethod, args, reply, err, c.enc, c.from, c.to, sTime, time.Now())
|
||||
@@ -69,20 +69,20 @@ type AnalyzerBiRPCConnector struct {
|
||||
to string
|
||||
}
|
||||
|
||||
func (c *AnalyzerBiRPCConnector) Call(serviceMethod string, args, reply interface{}) (err error) {
|
||||
func (c *AnalyzerBiRPCConnector) Call(serviceMethod string, args, reply any) (err error) {
|
||||
sTime := time.Now()
|
||||
err = c.conn.Call(serviceMethod, args, reply)
|
||||
go c.aS.logTrafic(0, serviceMethod, args, reply, err, c.enc, c.from, c.to, sTime, time.Now())
|
||||
return
|
||||
}
|
||||
|
||||
func (c *AnalyzerBiRPCConnector) CallBiRPC(cl rpcclient.ClientConnector, serviceMethod string, args, reply interface{}) (err error) {
|
||||
func (c *AnalyzerBiRPCConnector) CallBiRPC(cl rpcclient.ClientConnector, serviceMethod string, args, reply any) (err error) {
|
||||
sTime := time.Now()
|
||||
err = c.conn.CallBiRPC(cl, serviceMethod, args, reply)
|
||||
go c.aS.logTrafic(0, serviceMethod, args, reply, err, c.enc, c.from, c.to, sTime, time.Now())
|
||||
return
|
||||
}
|
||||
|
||||
func (c *AnalyzerBiRPCConnector) Handlers() map[string]interface{} {
|
||||
func (c *AnalyzerBiRPCConnector) Handlers() map[string]any {
|
||||
return c.conn.Handlers()
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
|
||||
type mockConnector struct{}
|
||||
|
||||
func (c *mockConnector) Call(_ string, _, _ interface{}) (err error) {
|
||||
func (c *mockConnector) Call(_ string, _, _ any) (err error) {
|
||||
return errors.New("error")
|
||||
}
|
||||
func TestNewAnalyzeConnector(t *testing.T) {
|
||||
@@ -66,10 +66,10 @@ func TestNewAnalyzeConnector(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *mockConnector) CallBiRPC(cl rpcclient.ClientConnector, serviceMethod string, args, reply interface{}) (err error) {
|
||||
func (c *mockConnector) CallBiRPC(cl rpcclient.ClientConnector, serviceMethod string, args, reply any) (err error) {
|
||||
return c.Call(serviceMethod, args, reply)
|
||||
}
|
||||
func (c *mockConnector) Handlers() map[string]interface{} { return make(map[string]interface{}) }
|
||||
func (c *mockConnector) Handlers() map[string]any { return make(map[string]any) }
|
||||
func TestNewAnalyzeBiRPCConnector1(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
|
||||
@@ -129,7 +129,7 @@ func TestNewAnalyzeBiRPCConnector2(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
exp := make(map[string]interface{})
|
||||
exp := make(map[string]any)
|
||||
if rply := rpc.Handlers(); !reflect.DeepEqual(rply, exp) {
|
||||
t.Errorf("Expected: %v ,received:%v", exp, rply)
|
||||
}
|
||||
|
||||
@@ -33,9 +33,9 @@ import (
|
||||
|
||||
// NewInfoRPC returns a structure to be indexed
|
||||
func NewInfoRPC(id uint64, method string,
|
||||
params, result, err interface{},
|
||||
params, result, err any,
|
||||
enc, from, to string, sTime, eTime time.Time) *InfoRPC {
|
||||
var e interface{}
|
||||
var e any
|
||||
switch val := err.(type) {
|
||||
default:
|
||||
case nil:
|
||||
@@ -73,16 +73,16 @@ type InfoRPC struct {
|
||||
|
||||
RequestID uint64
|
||||
RequestMethod string
|
||||
RequestParams interface{}
|
||||
Reply interface{}
|
||||
ReplyError interface{}
|
||||
RequestParams any
|
||||
Reply any
|
||||
ReplyError any
|
||||
}
|
||||
|
||||
type rpcAPI struct {
|
||||
ID uint64 `json:"id"`
|
||||
Method string `json:"method"`
|
||||
Params interface{} `json:"params"`
|
||||
Error string `json:"err,omitempty"`
|
||||
ID uint64 `json:"id"`
|
||||
Method string `json:"method"`
|
||||
Params any `json:"params"`
|
||||
Error string `json:"err,omitempty"`
|
||||
|
||||
StartTime time.Time
|
||||
}
|
||||
@@ -101,9 +101,9 @@ func getIndex(indx string) (indxType, storeType string) {
|
||||
return
|
||||
}
|
||||
|
||||
// unmarshalJSON will transform the message in a map[string]interface{} of []interface{}
|
||||
// unmarshalJSON will transform the message in a map[string]any of []any
|
||||
// depending of the first character
|
||||
func unmarshalJSON(jsn json.RawMessage) (interface{}, error) {
|
||||
func unmarshalJSON(jsn json.RawMessage) (any, error) {
|
||||
switch {
|
||||
case string(jsn) == "null" ||
|
||||
len(jsn) == 0: // nil or empty response
|
||||
@@ -118,11 +118,11 @@ func unmarshalJSON(jsn json.RawMessage) (interface{}, error) {
|
||||
case jsn[0] >= '0' && jsn[0] <= '9': // float64
|
||||
return strconv.ParseFloat(string(jsn), 64)
|
||||
case jsn[0] == '[': // slice
|
||||
var val []interface{}
|
||||
var val []any
|
||||
err := json.Unmarshal(jsn, &val)
|
||||
return val, err
|
||||
case jsn[0] == '{': // map
|
||||
var val map[string]interface{}
|
||||
var val map[string]any
|
||||
err := json.Unmarshal(jsn, &val)
|
||||
return val, err
|
||||
default:
|
||||
@@ -131,7 +131,7 @@ func unmarshalJSON(jsn json.RawMessage) (interface{}, error) {
|
||||
}
|
||||
|
||||
// getDPFromSearchresult will unmarshal the request and reply and populate a DataProvider
|
||||
// if the req is a map[string]interface{} we will try to put in *opts prefix the Opts field from req
|
||||
// if the req is a map[string]any we will try to put in *opts prefix the Opts field from req
|
||||
func getDPFromSearchresult(req, rep json.RawMessage, hdr utils.MapStorage) (utils.MapStorage, error) {
|
||||
repDP, err := unmarshalJSON(rep)
|
||||
if err != nil {
|
||||
@@ -141,8 +141,8 @@ func getDPFromSearchresult(req, rep json.RawMessage, hdr utils.MapStorage) (util
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var opts interface{}
|
||||
if reqMp, canCast := reqDP.(map[string]interface{}); canCast {
|
||||
var opts any
|
||||
if reqMp, canCast := reqDP.(map[string]any); canCast {
|
||||
opts = reqMp[utils.Opts]
|
||||
}
|
||||
return utils.MapStorage{
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestUnmarshalJSON(t *testing.T) {
|
||||
if _, err := unmarshalJSON(json.RawMessage(`a`)); err == nil || err.Error() != expErr.Error() {
|
||||
t.Errorf("Expected error: %s,received %+v", expErr, err)
|
||||
}
|
||||
var exp interface{} = true
|
||||
var exp any = true
|
||||
if val, err := unmarshalJSON(json.RawMessage(`true`)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(val, exp) {
|
||||
@@ -131,13 +131,13 @@ func TestUnmarshalJSON(t *testing.T) {
|
||||
t.Errorf("Expected: %s,received %s", utils.ToJSON(exp), utils.ToJSON(val))
|
||||
}
|
||||
|
||||
exp = []interface{}{"1", "2", "3"}
|
||||
exp = []any{"1", "2", "3"}
|
||||
if val, err := unmarshalJSON(json.RawMessage(`["1","2","3"]`)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(val, exp) {
|
||||
t.Errorf("Expected: %s,received %s", utils.ToJSON(exp), utils.ToJSON(val))
|
||||
}
|
||||
exp = map[string]interface{}{"1": "A", "2": "B", "3": "C"}
|
||||
exp = map[string]any{"1": "A", "2": "B", "3": "C"}
|
||||
if val, err := unmarshalJSON(json.RawMessage(`{"1":"A","2":"B","3":"C"}`)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(val, exp) {
|
||||
|
||||
Reference in New Issue
Block a user