diff --git a/api/http/common.go b/api/http/common.go index 9b0cfacde..4c7bf6b63 100644 --- a/api/http/common.go +++ b/api/http/common.go @@ -150,7 +150,7 @@ func ValidateUserName(name string) error { } // EncodeResponse encodes successful response. -func EncodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { +func EncodeResponse(_ context.Context, w http.ResponseWriter, response any) error { if ar, ok := response.(supermq.Response); ok { for k, v := range ar.Headers() { w.Header().Set(k, v) diff --git a/api/http/common_test.go b/api/http/common_test.go index c6b2fcce8..d1ab6ade0 100644 --- a/api/http/common_test.go +++ b/api/http/common_test.go @@ -115,7 +115,7 @@ func TestEncodeResponse(t *testing.T) { cases := []struct { desc string - resp interface{} + resp any header http.Header code int body []byte diff --git a/api/http/util/transport.go b/api/http/util/transport.go index fb78ee2a6..9b9abd536 100644 --- a/api/http/util/transport.go +++ b/api/http/util/transport.go @@ -39,7 +39,7 @@ func ReadStringQuery(r *http.Request, key, def string) (string, error) { } // ReadMetadataQuery reads the value of json http query parameters for a given key. -func ReadMetadataQuery(r *http.Request, key string, def map[string]interface{}) (map[string]interface{}, error) { +func ReadMetadataQuery(r *http.Request, key string, def map[string]any) (map[string]any, error) { vals := r.URL.Query()[key] if len(vals) > 1 { return nil, ErrInvalidQueryParams @@ -49,7 +49,7 @@ func ReadMetadataQuery(r *http.Request, key string, def map[string]interface{}) return def, nil } - m := make(map[string]interface{}) + m := make(map[string]any) err := json.Unmarshal([]byte(vals[0]), &m) if err != nil { return nil, errors.Wrap(ErrInvalidQueryParams, err) diff --git a/api/http/util/transport_test.go b/api/http/util/transport_test.go index cc8a59a95..76483ccd8 100644 --- a/api/http/util/transport_test.go +++ b/api/http/util/transport_test.go @@ -67,14 +67,14 @@ func TestReadMetadataQuery(t *testing.T) { desc string url string key string - ret map[string]interface{} + ret map[string]any err error }{ { desc: "valid metadata query", url: "http://localhost:8080/?key={\"test\":\"test\"}", key: "key", - ret: map[string]interface{}{"test": "test"}, + ret: map[string]any{"test": "test"}, err: nil, }, { @@ -177,7 +177,7 @@ func TestReadNumQuery(t *testing.T) { url string key string numType string - ret interface{} + ret any err error }{ { @@ -316,7 +316,7 @@ func TestReadNumQuery(t *testing.T) { assert.NoError(t, err) r := &http.Request{URL: parsedURL} - var ret interface{} + var ret any switch c.numType { case "int64": ret, err = apiutil.ReadNumQuery[int64](r, c.key, 0) diff --git a/auth/api/grpc/auth/client.go b/auth/api/grpc/auth/client.go index e80718b48..8b4797638 100644 --- a/auth/api/grpc/auth/client.go +++ b/auth/api/grpc/auth/client.go @@ -78,12 +78,12 @@ func (client authGrpcClient) Authenticate(ctx context.Context, token *grpcAuthV1 return &grpcAuthV1.AuthNRes{Id: ir.id, UserId: ir.userID, UserRole: uint32(ir.userRole)}, nil } -func encodeIdentifyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeIdentifyRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(authenticateReq) return &grpcAuthV1.AuthNReq{Token: req.token}, nil } -func decodeIdentifyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeIdentifyResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcAuthV1.AuthNRes) return authenticateRes{id: res.GetId(), userID: res.GetUserId(), userRole: auth.Role(res.UserRole)}, nil } @@ -100,7 +100,7 @@ func (client authGrpcClient) AuthenticatePAT(ctx context.Context, token *grpcAut return &grpcAuthV1.AuthNRes{Id: ir.id, UserId: ir.userID, UserRole: uint32(ir.userRole)}, nil } -func decodeIdentifyPATResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeIdentifyPATResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcAuthV1.AuthNRes) return authenticateRes{id: res.GetId(), userID: res.GetUserId(), userRole: auth.Role(res.UserRole)}, nil } @@ -127,12 +127,12 @@ func (client authGrpcClient) Authorize(ctx context.Context, req *grpcAuthV1.Auth return &grpcAuthV1.AuthZRes{Authorized: ar.authorized, Id: ar.id}, nil } -func decodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeAuthorizeResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcAuthV1.AuthZRes) return authorizeRes{authorized: res.Authorized, id: res.Id}, nil } -func encodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeAuthorizeRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(authReq) return &grpcAuthV1.AuthZReq{ Domain: req.Domain, @@ -166,7 +166,7 @@ func (client authGrpcClient) AuthorizePAT(ctx context.Context, req *grpcAuthV1.A return &grpcAuthV1.AuthZRes{Authorized: ar.authorized, Id: ar.id}, nil } -func encodeAuthorizePATRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeAuthorizePATRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(authPATReq) return &grpcAuthV1.AuthZPatReq{ UserId: req.userID, diff --git a/auth/api/grpc/auth/endpoint.go b/auth/api/grpc/auth/endpoint.go index 37003873d..c72c7e638 100644 --- a/auth/api/grpc/auth/endpoint.go +++ b/auth/api/grpc/auth/endpoint.go @@ -12,7 +12,7 @@ import ( ) func authenticateEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(authenticateReq) if err := req.validate(); err != nil { return authenticateRes{}, err @@ -28,7 +28,7 @@ func authenticateEndpoint(svc auth.Service) endpoint.Endpoint { } func authenticatePATEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(authenticateReq) if err := req.validate(); err != nil { return authenticateRes{}, err @@ -44,7 +44,7 @@ func authenticatePATEndpoint(svc auth.Service) endpoint.Endpoint { } func authorizeEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(authReq) if err := req.validate(); err != nil { @@ -68,7 +68,7 @@ func authorizeEndpoint(svc auth.Service) endpoint.Endpoint { } func authorizePATEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(authPATReq) if err := req.validate(); err != nil { diff --git a/auth/api/grpc/auth/server.go b/auth/api/grpc/auth/server.go index 3601249ea..2bc765d49 100644 --- a/auth/api/grpc/auth/server.go +++ b/auth/api/grpc/auth/server.go @@ -75,22 +75,22 @@ func (s *authGrpcServer) Authorize(ctx context.Context, req *grpcAuthV1.AuthZReq return res.(*grpcAuthV1.AuthZRes), nil } -func decodeAuthenticateRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeAuthenticateRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcAuthV1.AuthNReq) return authenticateReq{token: req.GetToken()}, nil } -func encodeAuthenticateResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeAuthenticateResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(authenticateRes) return &grpcAuthV1.AuthNRes{Id: res.id, UserId: res.userID, UserRole: uint32(res.userRole)}, nil } -func encodeAuthenticatePATResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeAuthenticatePATResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(authenticateRes) return &grpcAuthV1.AuthNRes{Id: res.id, UserId: res.userID, UserRole: uint32(res.userRole)}, nil } -func decodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeAuthorizeRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcAuthV1.AuthZReq) return authReq{ Domain: req.GetDomain(), @@ -104,12 +104,12 @@ func decodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{} }, nil } -func encodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeAuthorizeResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(authorizeRes) return &grpcAuthV1.AuthZRes{Authorized: res.authorized, Id: res.id}, nil } -func decodeAuthorizePATRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeAuthorizePATRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcAuthV1.AuthZPatReq) return authPATReq{ userID: req.GetUserId(), diff --git a/auth/api/grpc/token/client.go b/auth/api/grpc/token/client.go index d2fcc2db6..b747f3dea 100644 --- a/auth/api/grpc/token/client.go +++ b/auth/api/grpc/token/client.go @@ -63,7 +63,7 @@ func (client tokenGrpcClient) Issue(ctx context.Context, req *grpcTokenV1.IssueR return res.(*grpcTokenV1.Token), nil } -func encodeIssueRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeIssueRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(issueReq) return &grpcTokenV1.IssueReq{ UserId: req.userID, @@ -72,7 +72,7 @@ func encodeIssueRequest(_ context.Context, grpcReq interface{}) (interface{}, er }, nil } -func decodeIssueResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeIssueResponse(_ context.Context, grpcRes any) (any, error) { return grpcRes, nil } @@ -87,11 +87,11 @@ func (client tokenGrpcClient) Refresh(ctx context.Context, req *grpcTokenV1.Refr return res.(*grpcTokenV1.Token), nil } -func encodeRefreshRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRefreshRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(refreshReq) return &grpcTokenV1.RefreshReq{RefreshToken: req.refreshToken}, nil } -func decodeRefreshResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRefreshResponse(_ context.Context, grpcRes any) (any, error) { return grpcRes, nil } diff --git a/auth/api/grpc/token/endpoint.go b/auth/api/grpc/token/endpoint.go index 2ab3d59f0..6e4faa1d2 100644 --- a/auth/api/grpc/token/endpoint.go +++ b/auth/api/grpc/token/endpoint.go @@ -11,7 +11,7 @@ import ( ) func issueEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(issueReq) if err := req.validate(); err != nil { return issueRes{}, err @@ -36,7 +36,7 @@ func issueEndpoint(svc auth.Service) endpoint.Endpoint { } func refreshEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(refreshReq) if err := req.validate(); err != nil { return issueRes{}, err diff --git a/auth/api/grpc/token/server.go b/auth/api/grpc/token/server.go index d70f78abe..c8a79fa01 100644 --- a/auth/api/grpc/token/server.go +++ b/auth/api/grpc/token/server.go @@ -52,7 +52,7 @@ func (s *tokenGrpcServer) Refresh(ctx context.Context, req *grpcTokenV1.RefreshR return res.(*grpcTokenV1.Token), nil } -func decodeIssueRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeIssueRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcTokenV1.IssueReq) return issueReq{ userID: req.GetUserId(), @@ -61,12 +61,12 @@ func decodeIssueRequest(_ context.Context, grpcReq interface{}) (interface{}, er }, nil } -func decodeRefreshRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRefreshRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcTokenV1.RefreshReq) return refreshReq{refreshToken: req.GetRefreshToken()}, nil } -func encodeIssueResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeIssueResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(issueRes) return &grpcTokenV1.Token{ diff --git a/auth/api/http/keys/endpoint.go b/auth/api/http/keys/endpoint.go index d838db758..d168acd5b 100644 --- a/auth/api/http/keys/endpoint.go +++ b/auth/api/http/keys/endpoint.go @@ -12,7 +12,7 @@ import ( ) func issueEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(issueKeyReq) if err := req.validate(); err != nil { return nil, err @@ -44,7 +44,7 @@ func issueEndpoint(svc auth.Service) endpoint.Endpoint { } func retrieveEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(keyReq) if err := req.validate(); err != nil { @@ -71,7 +71,7 @@ func retrieveEndpoint(svc auth.Service) endpoint.Endpoint { } func revokeEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(keyReq) if err := req.validate(); err != nil { diff --git a/auth/api/http/keys/endpoint_test.go b/auth/api/http/keys/endpoint_test.go index 328af8435..d9e996f1c 100644 --- a/auth/api/http/keys/endpoint_test.go +++ b/auth/api/http/keys/endpoint_test.go @@ -90,7 +90,7 @@ func newServer(svc auth.Service) *httptest.Server { return httptest.NewServer(mux) } -func toJSON(data interface{}) string { +func toJSON(data any) string { jsonData, err := json.Marshal(data) if err != nil { return "" diff --git a/auth/api/http/keys/transport.go b/auth/api/http/keys/transport.go index 30e3e11de..689fc3255 100644 --- a/auth/api/http/keys/transport.go +++ b/auth/api/http/keys/transport.go @@ -50,7 +50,7 @@ func MakeHandler(svc auth.Service, mux *chi.Mux, logger *slog.Logger) *chi.Mux { return mux } -func decodeIssue(_ context.Context, r *http.Request) (interface{}, error) { +func decodeIssue(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), contentType) { return nil, apiutil.ErrUnsupportedContentType } @@ -63,7 +63,7 @@ func decodeIssue(_ context.Context, r *http.Request) (interface{}, error) { return req, nil } -func decodeKeyReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeKeyReq(_ context.Context, r *http.Request) (any, error) { req := keyReq{ token: apiutil.ExtractBearerToken(r), id: chi.URLParam(r, "id"), diff --git a/auth/api/http/pats/endpoint.go b/auth/api/http/pats/endpoint.go index ac50bfb2f..e653c3562 100644 --- a/auth/api/http/pats/endpoint.go +++ b/auth/api/http/pats/endpoint.go @@ -11,7 +11,7 @@ import ( ) func createPATEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(createPatReq) if err := req.validate(); err != nil { return nil, err @@ -27,7 +27,7 @@ func createPATEndpoint(svc auth.Service) endpoint.Endpoint { } func retrievePATEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrievePatReq) if err := req.validate(); err != nil { return nil, err @@ -43,7 +43,7 @@ func retrievePATEndpoint(svc auth.Service) endpoint.Endpoint { } func updatePATNameEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updatePatNameReq) if err := req.validate(); err != nil { return nil, err @@ -59,7 +59,7 @@ func updatePATNameEndpoint(svc auth.Service) endpoint.Endpoint { } func updatePATDescriptionEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updatePatDescriptionReq) if err := req.validate(); err != nil { return nil, err @@ -75,7 +75,7 @@ func updatePATDescriptionEndpoint(svc auth.Service) endpoint.Endpoint { } func listPATSEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listPatsReq) if err := req.validate(); err != nil { return nil, err @@ -98,7 +98,7 @@ func listPATSEndpoint(svc auth.Service) endpoint.Endpoint { } func deletePATEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(deletePatReq) if err := req.validate(); err != nil { return nil, err @@ -113,7 +113,7 @@ func deletePATEndpoint(svc auth.Service) endpoint.Endpoint { } func resetPATSecretEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(resetPatSecretReq) if err := req.validate(); err != nil { return nil, err @@ -129,7 +129,7 @@ func resetPATSecretEndpoint(svc auth.Service) endpoint.Endpoint { } func revokePATSecretEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(revokePatSecretReq) if err := req.validate(); err != nil { return nil, err @@ -144,7 +144,7 @@ func revokePATSecretEndpoint(svc auth.Service) endpoint.Endpoint { } func clearAllPATEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(clearAllPATReq) if err := req.validate(); err != nil { return nil, err @@ -159,7 +159,7 @@ func clearAllPATEndpoint(svc auth.Service) endpoint.Endpoint { } func addScopeEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(addScopeReq) if err := req.validate(); err != nil { return nil, err @@ -174,7 +174,7 @@ func addScopeEndpoint(svc auth.Service) endpoint.Endpoint { } func removeScopeEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(removeScopeReq) if err := req.validate(); err != nil { return nil, err @@ -189,7 +189,7 @@ func removeScopeEndpoint(svc auth.Service) endpoint.Endpoint { } func clearAllScopeEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(clearAllScopeReq) if err := req.validate(); err != nil { return nil, err @@ -204,7 +204,7 @@ func clearAllScopeEndpoint(svc auth.Service) endpoint.Endpoint { } func listScopesEndpoint(svc auth.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listScopesReq) if err := req.validate(); err != nil { return nil, err diff --git a/auth/api/http/pats/transport.go b/auth/api/http/pats/transport.go index f7058b0ec..829e298b7 100644 --- a/auth/api/http/pats/transport.go +++ b/auth/api/http/pats/transport.go @@ -130,7 +130,7 @@ func MakeHandler(svc auth.Service, mux *chi.Mux, logger *slog.Logger) *chi.Mux { return mux } -func decodeCreatePATRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeCreatePATRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), contentType) { return nil, apiutil.ErrUnsupportedContentType } @@ -145,7 +145,7 @@ func decodeCreatePATRequest(_ context.Context, r *http.Request) (interface{}, er return req, nil } -func decodeRetrievePATRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRetrievePATRequest(_ context.Context, r *http.Request) (any, error) { token := apiutil.ExtractBearerToken(r) if strings.HasPrefix(token, patPrefix) { return nil, apiutil.ErrUnsupportedTokenType @@ -158,7 +158,7 @@ func decodeRetrievePATRequest(_ context.Context, r *http.Request) (interface{}, return req, nil } -func decodeUpdatePATNameRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdatePATNameRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), contentType) { return nil, apiutil.ErrUnsupportedContentType } @@ -176,7 +176,7 @@ func decodeUpdatePATNameRequest(_ context.Context, r *http.Request) (interface{} return req, nil } -func decodeUpdatePATDescriptionRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdatePATDescriptionRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), contentType) { return nil, apiutil.ErrUnsupportedContentType } @@ -195,7 +195,7 @@ func decodeUpdatePATDescriptionRequest(_ context.Context, r *http.Request) (inte return req, nil } -func decodeListPATSRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeListPATSRequest(_ context.Context, r *http.Request) (any, error) { l, err := apiutil.ReadNumQuery[uint64](r, api.LimitKey, api.DefLimit) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -237,7 +237,7 @@ func decodeListPATSRequest(_ context.Context, r *http.Request) (interface{}, err return req, nil } -func decodeDeletePATRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeDeletePATRequest(_ context.Context, r *http.Request) (any, error) { token := apiutil.ExtractBearerToken(r) if strings.HasPrefix(token, patPrefix) { return nil, apiutil.ErrUnsupportedTokenType @@ -248,7 +248,7 @@ func decodeDeletePATRequest(_ context.Context, r *http.Request) (interface{}, er }, nil } -func decodeResetPATSecretRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeResetPATSecretRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), contentType) { return nil, apiutil.ErrUnsupportedContentType } @@ -267,7 +267,7 @@ func decodeResetPATSecretRequest(_ context.Context, r *http.Request) (interface{ return req, nil } -func decodeRevokePATSecretRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRevokePATSecretRequest(_ context.Context, r *http.Request) (any, error) { token := apiutil.ExtractBearerToken(r) if strings.HasPrefix(token, patPrefix) { return nil, apiutil.ErrUnsupportedTokenType @@ -278,7 +278,7 @@ func decodeRevokePATSecretRequest(_ context.Context, r *http.Request) (interface }, nil } -func decodeClearAllPATRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeClearAllPATRequest(_ context.Context, r *http.Request) (any, error) { token := apiutil.ExtractBearerToken(r) if strings.HasPrefix(token, patPrefix) { return nil, apiutil.ErrUnsupportedTokenType @@ -289,7 +289,7 @@ func decodeClearAllPATRequest(_ context.Context, r *http.Request) (interface{}, }, nil } -func decodeAddScopeRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeAddScopeRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), contentType) { return nil, apiutil.ErrUnsupportedContentType } @@ -311,7 +311,7 @@ func decodeAddScopeRequest(_ context.Context, r *http.Request) (interface{}, err return req, nil } -func decodeListScopeRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeListScopeRequest(_ context.Context, r *http.Request) (any, error) { l, err := apiutil.ReadNumQuery[uint64](r, api.LimitKey, api.DefLimit) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -333,7 +333,7 @@ func decodeListScopeRequest(_ context.Context, r *http.Request) (interface{}, er return req, nil } -func decodeRemoveScopeRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRemoveScopeRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), contentType) { return nil, apiutil.ErrUnsupportedContentType } @@ -353,7 +353,7 @@ func decodeRemoveScopeRequest(_ context.Context, r *http.Request) (interface{}, return req, nil } -func decodeClearAllScopeRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeClearAllScopeRequest(_ context.Context, r *http.Request) (any, error) { token := apiutil.ExtractBearerToken(r) if strings.HasPrefix(token, patPrefix) { return nil, apiutil.ErrUnsupportedTokenType diff --git a/certs/api/endpoint.go b/certs/api/endpoint.go index 77f58d780..25a1e19f6 100644 --- a/certs/api/endpoint.go +++ b/certs/api/endpoint.go @@ -13,7 +13,7 @@ import ( ) func issueCert(svc certs.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(addCertsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -38,7 +38,7 @@ func issueCert(svc certs.Service) endpoint.Endpoint { } func listSerials(svc certs.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -71,7 +71,7 @@ func listSerials(svc certs.Service) endpoint.Endpoint { } func viewCert(svc certs.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(viewReq) if err := req.validate(); err != nil { return certsRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -95,7 +95,7 @@ func viewCert(svc certs.Service) endpoint.Endpoint { } func revokeAllCerts(svc certs.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(revokeAllReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -111,7 +111,7 @@ func revokeAllCerts(svc certs.Service) endpoint.Endpoint { } func revokeBySerial(svc certs.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(revokeBySerialReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) diff --git a/certs/api/transport.go b/certs/api/transport.go index 3cb4f04bc..93dd559d0 100644 --- a/certs/api/transport.go +++ b/certs/api/transport.go @@ -83,7 +83,7 @@ func MakeHandler(svc certs.Service, authn smqauthn.Authentication, logger *slog. return r } -func decodeListCerts(_ context.Context, r *http.Request) (interface{}, error) { +func decodeListCerts(_ context.Context, r *http.Request) (any, error) { l, err := apiutil.ReadNumQuery[uint64](r, limitKey, defLimit) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -108,7 +108,7 @@ func decodeListCerts(_ context.Context, r *http.Request) (interface{}, error) { return req, nil } -func decodeViewCert(_ context.Context, r *http.Request) (interface{}, error) { +func decodeViewCert(_ context.Context, r *http.Request) (any, error) { req := viewReq{ serialID: chi.URLParam(r, "certID"), } @@ -116,7 +116,7 @@ func decodeViewCert(_ context.Context, r *http.Request) (interface{}, error) { return req, nil } -func decodeCerts(_ context.Context, r *http.Request) (interface{}, error) { +func decodeCerts(_ context.Context, r *http.Request) (any, error) { if r.Header.Get("Content-Type") != contentType { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -132,7 +132,7 @@ func decodeCerts(_ context.Context, r *http.Request) (interface{}, error) { return req, nil } -func decodeRevokeAllCerts(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRevokeAllCerts(_ context.Context, r *http.Request) (any, error) { req := revokeAllReq{ token: apiutil.ExtractBearerToken(r), clientID: chi.URLParam(r, "clientID"), @@ -142,7 +142,7 @@ func decodeRevokeAllCerts(_ context.Context, r *http.Request) (interface{}, erro return req, nil } -func decodeRevokeBySerial(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRevokeBySerial(_ context.Context, r *http.Request) (any, error) { req := revokeBySerialReq{ serialID: chi.URLParam(r, "certID"), } diff --git a/certs/pki/openbao/openbao.go b/certs/pki/openbao/openbao.go index c2a5aadb1..7c8e08c0b 100644 --- a/certs/pki/openbao/openbao.go +++ b/certs/pki/openbao/openbao.go @@ -88,7 +88,7 @@ func (va *openbaoPKIAgent) Issue(entityId, ttl string, ipAddrs []string) (certs. return certs.Cert{}, err } - secretValues := map[string]interface{}{ + secretValues := map[string]any{ "common_name": entityId, "ttl": ttl, "exclude_cn_from_sans": true, @@ -122,7 +122,7 @@ func (va *openbaoPKIAgent) Issue(entityId, ttl string, ipAddrs []string) (certs. if serialNumber, ok := secret.Data["serial_number"].(string); ok { cert.SerialNumber = serialNumber } - if caChain, ok := secret.Data["ca_chain"].([]interface{}); ok { + if caChain, ok := secret.Data["ca_chain"].([]any); ok { for _, ca := range caChain { if caStr, ok := ca.(string); ok { cert.CAChain = append(cert.CAChain, caStr) @@ -201,7 +201,7 @@ func (va *openbaoPKIAgent) Revoke(serialNumber string) error { return err } - secretValues := map[string]interface{}{ + secretValues := map[string]any{ "serial_number": serialNumber, } @@ -289,7 +289,7 @@ func (va *openbaoPKIAgent) LoginAndRenew() error { } } - authData := map[string]interface{}{ + authData := map[string]any{ "role_id": va.appRole, "secret_id": va.appSecret, } diff --git a/channels/api/grpc/client.go b/channels/api/grpc/client.go index 343430abd..39ce19bd2 100644 --- a/channels/api/grpc/client.go +++ b/channels/api/grpc/client.go @@ -100,7 +100,7 @@ func (client grpcClient) Authorize(ctx context.Context, req *grpcChannelsV1.Auth return &grpcChannelsV1.AuthzRes{Authorized: ar.authorized}, nil } -func encodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeAuthorizeRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(authorizeReq) return &grpcChannelsV1.AuthzReq{ @@ -112,7 +112,7 @@ func encodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{} }, nil } -func decodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeAuthorizeResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcChannelsV1.AuthzRes) return authorizeRes{authorized: res.GetAuthorized()}, nil @@ -129,11 +129,11 @@ func (client grpcClient) RemoveClientConnections(ctx context.Context, req *grpcC return &grpcChannelsV1.RemoveClientConnectionsRes{}, nil } -func encodeRemoveClientConnectionsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRemoveClientConnectionsRequest(_ context.Context, grpcReq any) (any, error) { return grpcReq.(*grpcChannelsV1.RemoveClientConnectionsReq), nil } -func decodeRemoveClientConnectionsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRemoveClientConnectionsResponse(_ context.Context, grpcRes any) (any, error) { return grpcRes.(*grpcChannelsV1.RemoveClientConnectionsRes), nil } @@ -148,11 +148,11 @@ func (client grpcClient) UnsetParentGroupFromChannels(ctx context.Context, req * return &grpcChannelsV1.UnsetParentGroupFromChannelsRes{}, nil } -func encodeUnsetParentGroupFromChannelsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeUnsetParentGroupFromChannelsRequest(_ context.Context, grpcReq any) (any, error) { return grpcReq.(*grpcChannelsV1.UnsetParentGroupFromChannelsReq), nil } -func decodeUnsetParentGroupFromChannelsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeUnsetParentGroupFromChannelsResponse(_ context.Context, grpcRes any) (any, error) { return grpcRes.(*grpcChannelsV1.UnsetParentGroupFromChannelsRes), nil } @@ -168,11 +168,11 @@ func (client grpcClient) RetrieveEntity(ctx context.Context, req *grpcCommonV1.R return res.(*grpcCommonV1.RetrieveEntityRes), nil } -func encodeRetrieveEntityRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRetrieveEntityRequest(_ context.Context, grpcReq any) (any, error) { return grpcReq.(*grpcCommonV1.RetrieveEntityReq), nil } -func decodeRetrieveEntityResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRetrieveEntityResponse(_ context.Context, grpcRes any) (any, error) { return grpcRes.(*grpcCommonV1.RetrieveEntityRes), nil } @@ -188,11 +188,11 @@ func (client grpcClient) RetrieveIDByRoute(ctx context.Context, req *grpcCommonV return res.(*grpcCommonV1.RetrieveEntityRes), nil } -func encodeRetrieveIDByRouteRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRetrieveIDByRouteRequest(_ context.Context, grpcReq any) (any, error) { return grpcReq.(*grpcCommonV1.RetrieveIDByRouteReq), nil } -func decodeRetrieveIDByRouteResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRetrieveIDByRouteResponse(_ context.Context, grpcRes any) (any, error) { return grpcRes.(*grpcCommonV1.RetrieveEntityRes), nil } diff --git a/channels/api/grpc/endpoint.go b/channels/api/grpc/endpoint.go index e71e6bf42..475f6df7b 100644 --- a/channels/api/grpc/endpoint.go +++ b/channels/api/grpc/endpoint.go @@ -12,7 +12,7 @@ import ( ) func authorizeEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(authorizeReq) if err := req.validate(); err != nil { return authorizeRes{}, err @@ -33,7 +33,7 @@ func authorizeEndpoint(svc channels.Service) endpoint.Endpoint { } func removeClientConnectionsEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(removeClientConnectionsReq) if err := svc.RemoveClientConnections(ctx, req.clientID); err != nil { @@ -45,7 +45,7 @@ func removeClientConnectionsEndpoint(svc channels.Service) endpoint.Endpoint { } func unsetParentGroupFromChannelsEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(unsetParentGroupFromChannelsReq) if err := svc.UnsetParentGroupFromChannels(ctx, req.parentGroupID); err != nil { @@ -57,7 +57,7 @@ func unsetParentGroupFromChannelsEndpoint(svc channels.Service) endpoint.Endpoin } func retrieveEntityEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveEntityReq) channel, err := svc.RetrieveByID(ctx, req.Id) if err != nil { @@ -69,7 +69,7 @@ func retrieveEntityEndpoint(svc channels.Service) endpoint.Endpoint { } func retrieveIDByRouteEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveIDByRouteReq) if err := req.validate(); err != nil { return retrieveIDByRouteRes{}, err diff --git a/channels/api/grpc/server.go b/channels/api/grpc/server.go index 57b854239..a532a6fc7 100644 --- a/channels/api/grpc/server.go +++ b/channels/api/grpc/server.go @@ -69,7 +69,7 @@ func (s *grpcServer) Authorize(ctx context.Context, req *grpcChannelsV1.AuthzReq return res.(*grpcChannelsV1.AuthzRes), nil } -func decodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeAuthorizeRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcChannelsV1.AuthzReq) connType := connections.ConnType(req.GetType()) @@ -85,7 +85,7 @@ func decodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{} }, nil } -func encodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeAuthorizeResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(authorizeRes) return &grpcChannelsV1.AuthzRes{Authorized: res.authorized}, nil } @@ -98,7 +98,7 @@ func (s *grpcServer) RemoveClientConnections(ctx context.Context, req *grpcChann return res.(*grpcChannelsV1.RemoveClientConnectionsRes), nil } -func decodeRemoveClientConnectionsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRemoveClientConnectionsRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcChannelsV1.RemoveClientConnectionsReq) return removeClientConnectionsReq{ @@ -106,7 +106,7 @@ func decodeRemoveClientConnectionsRequest(_ context.Context, grpcReq interface{} }, nil } -func encodeRemoveClientConnectionsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeRemoveClientConnectionsResponse(_ context.Context, grpcRes any) (any, error) { _ = grpcRes.(removeClientConnectionsRes) return &grpcChannelsV1.RemoveClientConnectionsRes{}, nil } @@ -119,7 +119,7 @@ func (s *grpcServer) UnsetParentGroupFromChannels(ctx context.Context, req *grpc return res.(*grpcChannelsV1.UnsetParentGroupFromChannelsRes), nil } -func decodeUnsetParentGroupFromChannelsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeUnsetParentGroupFromChannelsRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcChannelsV1.UnsetParentGroupFromChannelsReq) return unsetParentGroupFromChannelsReq{ @@ -127,7 +127,7 @@ func decodeUnsetParentGroupFromChannelsRequest(_ context.Context, grpcReq interf }, nil } -func encodeUnsetParentGroupFromChannelsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeUnsetParentGroupFromChannelsResponse(_ context.Context, grpcRes any) (any, error) { _ = grpcRes.(unsetParentGroupFromChannelsRes) return &grpcChannelsV1.UnsetParentGroupFromChannelsRes{}, nil } @@ -140,14 +140,14 @@ func (s *grpcServer) RetrieveEntity(ctx context.Context, req *grpcCommonV1.Retri return res.(*grpcCommonV1.RetrieveEntityRes), nil } -func decodeRetrieveEntityRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRetrieveEntityRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcCommonV1.RetrieveEntityReq) return retrieveEntityReq{ Id: req.GetId(), }, nil } -func encodeRetrieveEntityResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeRetrieveEntityResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(retrieveEntityRes) return &grpcCommonV1.RetrieveEntityRes{ @@ -160,7 +160,7 @@ func encodeRetrieveEntityResponse(_ context.Context, grpcRes interface{}) (inter }, nil } -func decodeRetrieveIDByRouteRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRetrieveIDByRouteRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcCommonV1.RetrieveIDByRouteReq) return retrieveIDByRouteReq{ route: req.GetRoute(), @@ -168,7 +168,7 @@ func decodeRetrieveIDByRouteRequest(_ context.Context, grpcReq interface{}) (int }, nil } -func encodeRetrieveIDByRouteResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeRetrieveIDByRouteResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(retrieveIDByRouteRes) return &grpcCommonV1.RetrieveEntityRes{ diff --git a/channels/api/http/decode.go b/channels/api/http/decode.go index 06069682a..45e94a1dc 100644 --- a/channels/api/http/decode.go +++ b/channels/api/http/decode.go @@ -17,7 +17,7 @@ import ( "github.com/go-chi/chi/v5" ) -func decodeViewChannel(_ context.Context, r *http.Request) (interface{}, error) { +func decodeViewChannel(_ context.Context, r *http.Request) (any, error) { roles, err := apiutil.ReadBoolQuery(r, api.RolesKey, false) if err != nil { return viewChannelReq{}, errors.Wrap(apiutil.ErrValidation, err) @@ -31,7 +31,7 @@ func decodeViewChannel(_ context.Context, r *http.Request) (interface{}, error) return req, nil } -func decodeCreateChannelReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeCreateChannelReq(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -44,7 +44,7 @@ func decodeCreateChannelReq(_ context.Context, r *http.Request) (interface{}, er return req, nil } -func decodeCreateChannelsReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeCreateChannelsReq(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -57,7 +57,7 @@ func decodeCreateChannelsReq(_ context.Context, r *http.Request) (interface{}, e return req, nil } -func decodeListChannels(_ context.Context, r *http.Request) (interface{}, error) { +func decodeListChannels(_ context.Context, r *http.Request) (any, error) { name, err := apiutil.ReadStringQuery(r, api.NameKey, "") if err != nil { return listChannelsReq{}, errors.Wrap(apiutil.ErrValidation, err) @@ -174,7 +174,7 @@ func decodeListChannels(_ context.Context, r *http.Request) (interface{}, error) return req, nil } -func decodeUpdateChannel(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateChannel(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -189,7 +189,7 @@ func decodeUpdateChannel(_ context.Context, r *http.Request) (interface{}, error return req, nil } -func decodeUpdateChannelTags(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateChannelTags(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -204,7 +204,7 @@ func decodeUpdateChannelTags(_ context.Context, r *http.Request) (interface{}, e return req, nil } -func decodeSetChannelParentGroupStatus(_ context.Context, r *http.Request) (interface{}, error) { +func decodeSetChannelParentGroupStatus(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -218,7 +218,7 @@ func decodeSetChannelParentGroupStatus(_ context.Context, r *http.Request) (inte return req, nil } -func decodeRemoveChannelParentGroupStatus(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRemoveChannelParentGroupStatus(_ context.Context, r *http.Request) (any, error) { req := removeChannelParentGroupReq{ id: chi.URLParam(r, "channelID"), } @@ -226,7 +226,7 @@ func decodeRemoveChannelParentGroupStatus(_ context.Context, r *http.Request) (i return req, nil } -func decodeChangeChannelStatus(_ context.Context, r *http.Request) (interface{}, error) { +func decodeChangeChannelStatus(_ context.Context, r *http.Request) (any, error) { req := changeChannelStatusReq{ id: chi.URLParam(r, "channelID"), } @@ -234,14 +234,14 @@ func decodeChangeChannelStatus(_ context.Context, r *http.Request) (interface{}, return req, nil } -func decodeDeleteChannelReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeDeleteChannelReq(_ context.Context, r *http.Request) (any, error) { req := deleteChannelReq{ id: chi.URLParam(r, "channelID"), } return req, nil } -func decodeConnectChannelClientRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeConnectChannelClientRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -255,7 +255,7 @@ func decodeConnectChannelClientRequest(_ context.Context, r *http.Request) (inte return req, nil } -func decodeDisconnectChannelClientsRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeDisconnectChannelClientsRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -269,7 +269,7 @@ func decodeDisconnectChannelClientsRequest(_ context.Context, r *http.Request) ( return req, nil } -func decodeConnectRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeConnectRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -282,7 +282,7 @@ func decodeConnectRequest(_ context.Context, r *http.Request) (interface{}, erro return req, nil } -func decodeDisconnectRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeDisconnectRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } diff --git a/channels/api/http/endpoint_test.go b/channels/api/http/endpoint_test.go index bb0f5af82..ecc3efa51 100644 --- a/channels/api/http/endpoint_test.go +++ b/channels/api/http/endpoint_test.go @@ -69,7 +69,7 @@ func TestCreateChannelEndpoint(t *testing.T) { reqChannel := channels.Channel{ Name: valid, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, Route: valid, @@ -145,7 +145,7 @@ func TestCreateChannelEndpoint(t *testing.T) { domainID: validID, req: channels.Channel{ Name: strings.Repeat("a", 1025), - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, }, @@ -238,7 +238,7 @@ func TestCreateChannelsEndpoint(t *testing.T) { reqChannels := []channels.Channel{ { Name: valid, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, Route: valid, @@ -304,7 +304,7 @@ func TestCreateChannelsEndpoint(t *testing.T) { req: []channels.Channel{ { Name: strings.Repeat("a", 1025), - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, }, @@ -824,7 +824,7 @@ func TestUpdateChannelEndpoint(t *testing.T) { updateChannelReq := channels.Channel{ ID: validID, Name: valid, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, } @@ -895,7 +895,7 @@ func TestUpdateChannelEndpoint(t *testing.T) { updateReq: channels.Channel{ ID: validID, Name: strings.Repeat("a", 1025), - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, }, @@ -1843,7 +1843,7 @@ func TestConnectEndpoint(t *testing.T) { url: fmt.Sprintf("%s/%s/channels/connect", gs.URL, tc.domainID), token: tc.token, contentType: contentType, - body: strings.NewReader(toJSON(map[string]interface{}{ + body: strings.NewReader(toJSON(map[string]any{ "channel_ids": tc.channelIDs, "client_ids": tc.clientIDs, "types": tc.types, @@ -1973,7 +1973,7 @@ func TestDisconnectEndpoint(t *testing.T) { url: fmt.Sprintf("%s/%s/channels/disconnect", gs.URL, tc.domainID), token: tc.token, contentType: contentType, - body: strings.NewReader(toJSON(map[string]interface{}{ + body: strings.NewReader(toJSON(map[string]any{ "channel_ids": tc.channelIDs, "client_ids": tc.clientIDs, "types": tc.types, @@ -2104,7 +2104,7 @@ func (tr testRequest) make() (*http.Response, error) { return tr.client.Do(req) } -func toJSON(data interface{}) string { +func toJSON(data any) string { jsonData, err := json.Marshal(data) if err != nil { return "" diff --git a/channels/api/http/endpoints.go b/channels/api/http/endpoints.go index b9610a602..cdfcd3f0a 100644 --- a/channels/api/http/endpoints.go +++ b/channels/api/http/endpoints.go @@ -16,7 +16,7 @@ import ( ) func createChannelEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(createChannelReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -40,7 +40,7 @@ func createChannelEndpoint(svc channels.Service) endpoint.Endpoint { } func createChannelsEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(createChannelsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -71,7 +71,7 @@ func createChannelsEndpoint(svc channels.Service) endpoint.Endpoint { } func viewChannelEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(viewChannelReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -92,7 +92,7 @@ func viewChannelEndpoint(svc channels.Service) endpoint.Endpoint { } func listChannelsEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listChannelsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -132,7 +132,7 @@ func listChannelsEndpoint(svc channels.Service) endpoint.Endpoint { } func updateChannelEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateChannelReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -158,7 +158,7 @@ func updateChannelEndpoint(svc channels.Service) endpoint.Endpoint { } func updateChannelTagsEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateChannelTagsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -183,7 +183,7 @@ func updateChannelTagsEndpoint(svc channels.Service) endpoint.Endpoint { } func setChannelParentGroupEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(setChannelParentGroupReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -203,7 +203,7 @@ func setChannelParentGroupEndpoint(svc channels.Service) endpoint.Endpoint { } func removeChannelParentGroupEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(removeChannelParentGroupReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -223,7 +223,7 @@ func removeChannelParentGroupEndpoint(svc channels.Service) endpoint.Endpoint { } func enableChannelEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(changeChannelStatusReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -244,7 +244,7 @@ func enableChannelEndpoint(svc channels.Service) endpoint.Endpoint { } func disableChannelEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(changeChannelStatusReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -265,7 +265,7 @@ func disableChannelEndpoint(svc channels.Service) endpoint.Endpoint { } func connectChannelClientEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(connectChannelClientsRequest) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -285,7 +285,7 @@ func connectChannelClientEndpoint(svc channels.Service) endpoint.Endpoint { } func disconnectChannelClientsEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(disconnectChannelClientsRequest) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -305,7 +305,7 @@ func disconnectChannelClientsEndpoint(svc channels.Service) endpoint.Endpoint { } func connectEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(connectRequest) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -325,7 +325,7 @@ func connectEndpoint(svc channels.Service) endpoint.Endpoint { } func disconnectEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(disconnectRequest) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -345,7 +345,7 @@ func disconnectEndpoint(svc channels.Service) endpoint.Endpoint { } func deleteChannelEndpoint(svc channels.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(deleteChannelReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) diff --git a/channels/api/http/requests.go b/channels/api/http/requests.go index fad052202..2ff561ffe 100644 --- a/channels/api/http/requests.go +++ b/channels/api/http/requests.go @@ -108,9 +108,9 @@ func (req listChannelsReq) validate() error { type updateChannelReq struct { id string - Name string `json:"name,omitempty"` - Metadata map[string]interface{} `json:"metadata,omitempty"` - Tags []string `json:"tags,omitempty"` + Name string `json:"name,omitempty"` + Metadata map[string]any `json:"metadata,omitempty"` + Tags []string `json:"tags,omitempty"` } func (req updateChannelReq) validate() error { diff --git a/channels/channels.go b/channels/channels.go index 827131f09..716513e0b 100644 --- a/channels/channels.go +++ b/channels/channels.go @@ -14,7 +14,7 @@ import ( ) // Metadata represents arbitrary JSON. -type Metadata map[string]interface{} +type Metadata map[string]any // Channel represents a SuperMQ "communication topic". This topic // contains the clients that can exchange messages between each other. diff --git a/channels/events/events.go b/channels/events/events.go index 355dfb8c5..42bc1d7db 100644 --- a/channels/events/events.go +++ b/channels/events/events.go @@ -48,8 +48,8 @@ type createChannelEvent struct { requestID string } -func (cce createChannelEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (cce createChannelEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": channelCreate, "id": cce.ID, "roles_provisioned": cce.rolesProvisioned, @@ -83,8 +83,8 @@ type updateChannelEvent struct { requestID string } -func (uce updateChannelEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (uce updateChannelEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": uce.operation, "updated_at": uce.UpdatedAt, "updated_by": uce.UpdatedBy, @@ -130,8 +130,8 @@ type changeChannelStatusEvent struct { requestID string } -func (cse changeChannelStatusEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (cse changeChannelStatusEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": cse.operation, "id": cse.id, "status": cse.status, @@ -151,8 +151,8 @@ type viewChannelEvent struct { requestID string } -func (vce viewChannelEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (vce viewChannelEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": channelView, "id": vce.ID, "domain": vce.DomainID, @@ -196,8 +196,8 @@ type listChannelEvent struct { requestID string } -func (lce listChannelEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (lce listChannelEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": channelList, "total": lce.Total, "offset": lce.Offset, @@ -241,8 +241,8 @@ type listUserChannelsEvent struct { requestID string } -func (luce listUserChannelsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (luce listUserChannelsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": channelListByUser, "req_user_id": luce.userID, "total": luce.Total, @@ -289,8 +289,8 @@ type removeChannelEvent struct { requestID string } -func (dce removeChannelEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (dce removeChannelEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": channelRemove, "id": dce.id, "domain": dce.DomainID, @@ -309,8 +309,8 @@ type connectEvent struct { requestID string } -func (ce connectEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (ce connectEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": channelConnect, "client_ids": ce.thIDs, "channel_ids": ce.chIDs, @@ -331,8 +331,8 @@ type disconnectEvent struct { requestID string } -func (de disconnectEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (de disconnectEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": channelDisconnect, "client_ids": de.thIDs, "channel_ids": de.chIDs, @@ -352,8 +352,8 @@ type setParentGroupEvent struct { requestID string } -func (spge setParentGroupEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (spge setParentGroupEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": channelSetParent, "id": spge.id, "parent_group_id": spge.parentGroupID, @@ -371,8 +371,8 @@ type removeParentGroupEvent struct { requestID string } -func (rpge removeParentGroupEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (rpge removeParentGroupEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": channelRemoveParent, "id": rpge.id, "domain": rpge.DomainID, diff --git a/channels/middleware/authorization.go b/channels/middleware/authorization.go index 8de28bb9b..9737685d6 100644 --- a/channels/middleware/authorization.go +++ b/channels/middleware/authorization.go @@ -644,7 +644,7 @@ func (am *authorizationMiddleware) checkSuperAdmin(ctx context.Context, userID s return nil } -func (am *authorizationMiddleware) callOut(ctx context.Context, session authn.Session, op string, params map[string]interface{}) error { +func (am *authorizationMiddleware) callOut(ctx context.Context, session authn.Session, op string, params map[string]any) error { pl := map[string]any{ "entity_type": policies.ChannelType, "subject_type": policies.UserType, diff --git a/channels/postgres/channels.go b/channels/postgres/channels.go index 83b7fcea1..3462fd505 100644 --- a/channels/postgres/channels.go +++ b/channels/postgres/channels.go @@ -349,7 +349,7 @@ func (cr *channelRepository) RetrieveByIDWithRoles(ctx context.Context, id, memb FROM channels c2 JOIN final_roles fr ON fr.channel_id = c2.id ` - parameters := map[string]interface{}{ + parameters := map[string]any{ "id": id, "member_id": memberID, } @@ -894,7 +894,7 @@ final_channels AS ( func (cr *channelRepository) Remove(ctx context.Context, ids ...string) error { q := "DELETE FROM channels AS c WHERE c.id = ANY(:channel_ids) ;" - params := map[string]interface{}{ + params := map[string]any{ "channel_ids": ids, } result, err := cr.db.NamedExecContext(ctx, q, params) diff --git a/channels/postgres/channels_test.go b/channels/postgres/channels_test.go index 01e21e9be..7ba90004b 100644 --- a/channels/postgres/channels_test.go +++ b/channels/postgres/channels_test.go @@ -31,7 +31,7 @@ var ( Name: namegen.Generate(), Route: testsutil.GenerateUUID(&testing.T{}), Tags: []string{"tag1", "tag2"}, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: channels.EnabledStatus, ConnectionTypes: []connections.ConnType{}, @@ -92,7 +92,7 @@ func TestSave(t *testing.T) { ID: invalidID, Domain: testsutil.GenerateUUID(t), Name: namegen.Generate(), - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: channels.EnabledStatus, }, @@ -105,7 +105,7 @@ func TestSave(t *testing.T) { ID: testsutil.GenerateUUID(t), Domain: invalidID, Name: namegen.Generate(), - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: channels.EnabledStatus, }, @@ -118,7 +118,7 @@ func TestSave(t *testing.T) { ID: testsutil.GenerateUUID(t), Domain: testsutil.GenerateUUID(t), Name: strings.Repeat("a", 1025), - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: channels.EnabledStatus, }, @@ -131,7 +131,7 @@ func TestSave(t *testing.T) { ID: testsutil.GenerateUUID(t), Domain: testsutil.GenerateUUID(t), Name: namegen.Generate(), - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), @@ -146,7 +146,7 @@ func TestSave(t *testing.T) { ID: duplicateChannelID, Domain: validChannel.Domain, Name: validChannel.Name, - Metadata: map[string]interface{}{"key": "different_value"}, + Metadata: map[string]any{"key": "different_value"}, CreatedAt: validTimestamp, Status: channels.EnabledStatus, }, @@ -155,7 +155,7 @@ func TestSave(t *testing.T) { ID: duplicateChannelID, Domain: validChannel.Domain, Name: validChannel.Name, - Metadata: map[string]interface{}{"key": "different_value"}, + Metadata: map[string]any{"key": "different_value"}, CreatedAt: validTimestamp, Status: channels.EnabledStatus, ConnectionTypes: []connections.ConnType{}, @@ -209,7 +209,7 @@ func TestUpdate(t *testing.T) { ID: validChannel.ID, Name: namegen.Generate(), Route: testsutil.GenerateUUID(t), - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -231,7 +231,7 @@ func TestUpdate(t *testing.T) { update: "metadata", channel: channels.Channel{ ID: validChannel.ID, - Metadata: map[string]interface{}{"key1": "value1"}, + Metadata: map[string]any{"key1": "value1"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -243,7 +243,7 @@ func TestUpdate(t *testing.T) { channel: channels.Channel{ ID: testsutil.GenerateUUID(t), Name: namegen.Generate(), - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -254,7 +254,7 @@ func TestUpdate(t *testing.T) { update: "all", channel: channels.Channel{ Name: namegen.Generate(), - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -551,7 +551,7 @@ func TestRetrieveAll(t *testing.T) { ParentGroup: parentID, Name: name, Route: testsutil.GenerateUUID(t), - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: channels.EnabledStatus, ConnectionTypes: []connections.ConnType{}, @@ -772,7 +772,7 @@ func TestRetrieveAll(t *testing.T) { Page: channels.Page{ Offset: 0, Limit: 10, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, }, @@ -1489,7 +1489,7 @@ func TestRetrieveParentGroupChannels(t *testing.T) { Domain: testsutil.GenerateUUID(t), ParentGroup: parentID, Name: name, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: channels.EnabledStatus, ConnectionTypes: []connections.ConnType{}, @@ -1557,7 +1557,7 @@ func TestUnsetParentGroupFromChannels(t *testing.T) { Domain: testsutil.GenerateUUID(t), ParentGroup: parentID, Name: name, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: channels.EnabledStatus, } diff --git a/channels/service_test.go b/channels/service_test.go index b0fa1c15c..fe9143afa 100644 --- a/channels/service_test.go +++ b/channels/service_test.go @@ -39,7 +39,7 @@ var ( ID: testsutil.GenerateUUID(&testing.T{}), Name: namegen.Generate(), Route: namegen.Generate(), - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": "value", }, Tags: []string{"tag1", "tag2"}, @@ -50,7 +50,7 @@ var ( ID: testsutil.GenerateUUID(&testing.T{}), Name: namegen.Generate(), Route: namegen.Generate(), - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": "value", }, Tags: []string{"tag1", "tag2"}, diff --git a/cli/clients_test.go b/cli/clients_test.go index 3195dd1f2..8f9cc15a4 100644 --- a/cli/clients_test.go +++ b/cli/clients_test.go @@ -292,8 +292,8 @@ func TestUpdateClientCmd(t *testing.T) { }, client: smqsdk.Client{ Name: "clientName", - Metadata: map[string]interface{}{ - "metadata": map[string]interface{}{ + Metadata: map[string]any{ + "metadata": map[string]any{ "role": "general", }, }, diff --git a/cli/config.go b/cli/config.go index f94870b89..22b1f1501 100644 --- a/cli/config.go +++ b/cli/config.go @@ -250,7 +250,7 @@ func setConfigValue(key, value string) error { } } - configKeyToField := map[string]interface{}{ + configKeyToField := map[string]any{ "clients_url": &config.Remotes.ClientsURL, "users_url": &config.Remotes.UsersURL, "http_adapter_url": &config.Remotes.HTTPAdapterURL, diff --git a/cli/utils.go b/cli/utils.go index 4817ffbb6..8ed5aef9f 100644 --- a/cli/utils.go +++ b/cli/utils.go @@ -44,7 +44,7 @@ var ( LastName string = "" ) -func logJSONCmd(cmd cobra.Command, iList ...interface{}) { +func logJSONCmd(cmd cobra.Command, iList ...any) { for _, i := range iList { m, err := json.Marshal(i) if err != nil { @@ -85,8 +85,8 @@ func logRevokedTimeCmd(cmd cobra.Command, t time.Time) { } } -func convertMetadata(m string) (map[string]interface{}, error) { - var metadata map[string]interface{} +func convertMetadata(m string) (map[string]any, error) { + var metadata map[string]any if m == "" { return nil, nil } diff --git a/clients/api/grpc/client.go b/clients/api/grpc/client.go index ace45282a..3cb3ea546 100644 --- a/clients/api/grpc/client.go +++ b/clients/api/grpc/client.go @@ -121,14 +121,14 @@ func (client grpcClient) Authenticate(ctx context.Context, req *grpcClientsV1.Au return &grpcClientsV1.AuthnRes{Authenticated: ar.authenticated, Id: ar.id}, nil } -func encodeAuthenticateRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeAuthenticateRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(authenticateReq) return &grpcClientsV1.AuthnReq{ Token: req.Token, }, nil } -func decodeAuthenticateResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeAuthenticateResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcClientsV1.AuthnRes) return authenticateRes{authenticated: res.GetAuthenticated(), id: res.GetId()}, nil } @@ -147,14 +147,14 @@ func (client grpcClient) RetrieveEntity(ctx context.Context, req *grpcCommonV1.R return &grpcCommonV1.RetrieveEntityRes{Entity: &grpcCommonV1.EntityBasic{Id: ebr.id, DomainId: ebr.domain, Status: uint32(ebr.status)}}, nil } -func encodeRetrieveEntityRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRetrieveEntityRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(string) return &grpcCommonV1.RetrieveEntityReq{ Id: req, }, nil } -func decodeRetrieveEntityResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRetrieveEntityResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcCommonV1.RetrieveEntityRes) return retrieveEntityRes{ @@ -187,14 +187,14 @@ func (client grpcClient) RetrieveEntities(ctx context.Context, req *grpcCommonV1 return &grpcCommonV1.RetrieveEntitiesRes{Total: ep.total, Limit: ep.limit, Offset: ep.offset, Entities: entities}, nil } -func encodeRetrieveEntitiesRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRetrieveEntitiesRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.([]string) return &grpcCommonV1.RetrieveEntitiesReq{ Ids: req, }, nil } -func decodeRetrieveEntitiesResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRetrieveEntitiesResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcCommonV1.RetrieveEntitiesRes) clis := []entity{} @@ -234,7 +234,7 @@ func (client grpcClient) AddConnections(ctx context.Context, req *grpcCommonV1.A return &grpcCommonV1.AddConnectionsRes{Ok: cr.ok}, nil } -func encodeAddConnectionsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeAddConnectionsRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.([]clients.Connection) conns := []*grpcCommonV1.Connection{} @@ -252,7 +252,7 @@ func encodeAddConnectionsRequest(_ context.Context, grpcReq interface{}) (interf }, nil } -func decodeAddConnectionsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeAddConnectionsResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcCommonV1.AddConnectionsRes) return connectionsRes{ok: res.GetOk()}, nil @@ -282,7 +282,7 @@ func (client grpcClient) RemoveConnections(ctx context.Context, req *grpcCommonV return &grpcCommonV1.RemoveConnectionsRes{Ok: cr.ok}, nil } -func encodeRemoveConnectionsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRemoveConnectionsRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.([]clients.Connection) conns := []*grpcCommonV1.Connection{} @@ -300,7 +300,7 @@ func encodeRemoveConnectionsRequest(_ context.Context, grpcReq interface{}) (int }, nil } -func decodeRemoveConnectionsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRemoveConnectionsResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcCommonV1.RemoveConnectionsRes) return connectionsRes{ok: res.GetOk()}, nil @@ -317,11 +317,11 @@ func (client grpcClient) RemoveChannelConnections(ctx context.Context, req *grpc return &grpcClientsV1.RemoveChannelConnectionsRes{}, nil } -func encodeRemoveChannelConnectionsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRemoveChannelConnectionsRequest(_ context.Context, grpcReq any) (any, error) { return grpcReq.(*grpcClientsV1.RemoveChannelConnectionsReq), nil } -func decodeRemoveChannelConnectionsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRemoveChannelConnectionsResponse(_ context.Context, grpcRes any) (any, error) { return grpcRes.(*grpcClientsV1.RemoveChannelConnectionsRes), nil } @@ -336,11 +336,11 @@ func (client grpcClient) UnsetParentGroupFromClient(ctx context.Context, req *gr return &grpcClientsV1.UnsetParentGroupFromClientRes{}, nil } -func encodeUnsetParentGroupFromClientRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeUnsetParentGroupFromClientRequest(_ context.Context, grpcReq any) (any, error) { return grpcReq.(*grpcClientsV1.UnsetParentGroupFromClientReq), nil } -func decodeUnsetParentGroupFromClientResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeUnsetParentGroupFromClientResponse(_ context.Context, grpcRes any) (any, error) { return grpcRes.(*grpcClientsV1.UnsetParentGroupFromClientRes), nil } diff --git a/clients/api/grpc/endpoint.go b/clients/api/grpc/endpoint.go index d84a7b366..1aa47710c 100644 --- a/clients/api/grpc/endpoint.go +++ b/clients/api/grpc/endpoint.go @@ -12,7 +12,7 @@ import ( ) func authenticateEndpoint(svc pClients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(authenticateReq) id, err := svc.Authenticate(ctx, req.Token) if err != nil { @@ -26,7 +26,7 @@ func authenticateEndpoint(svc pClients.Service) endpoint.Endpoint { } func retrieveEntityEndpoint(svc pClients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveEntityReq) client, err := svc.RetrieveById(ctx, req.Id) if err != nil { @@ -38,7 +38,7 @@ func retrieveEntityEndpoint(svc pClients.Service) endpoint.Endpoint { } func retrieveEntitiesEndpoint(svc pClients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveEntitiesReq) tp, err := svc.RetrieveByIds(ctx, req.Ids) if err != nil { @@ -58,7 +58,7 @@ func retrieveEntitiesEndpoint(svc pClients.Service) endpoint.Endpoint { } func addConnectionsEndpoint(svc pClients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(connectionsReq) var conns []clients.Connection @@ -81,7 +81,7 @@ func addConnectionsEndpoint(svc pClients.Service) endpoint.Endpoint { } func removeConnectionsEndpoint(svc pClients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(connectionsReq) var conns []clients.Connection @@ -103,7 +103,7 @@ func removeConnectionsEndpoint(svc pClients.Service) endpoint.Endpoint { } func removeChannelConnectionsEndpoint(svc pClients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(removeChannelConnectionsReq) if err := svc.RemoveChannelConnections(ctx, req.channelID); err != nil { @@ -115,7 +115,7 @@ func removeChannelConnectionsEndpoint(svc pClients.Service) endpoint.Endpoint { } func UnsetParentGroupFromClientEndpoint(svc pClients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(UnsetParentGroupFromClientReq) if err := svc.UnsetParentGroupFromClient(ctx, req.parentGroupID); err != nil { diff --git a/clients/api/grpc/server.go b/clients/api/grpc/server.go index 3f1880f7e..164e7c645 100644 --- a/clients/api/grpc/server.go +++ b/clients/api/grpc/server.go @@ -81,14 +81,14 @@ func (s *grpcServer) Authenticate(ctx context.Context, req *grpcClientsV1.AuthnR return res.(*grpcClientsV1.AuthnRes), nil } -func decodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeAuthorizeRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcClientsV1.AuthnReq) return authenticateReq{ Token: req.GetToken(), }, nil } -func encodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeAuthorizeResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(authenticateRes) return &grpcClientsV1.AuthnRes{Authenticated: res.authenticated, Id: res.id}, nil } @@ -101,14 +101,14 @@ func (s *grpcServer) RetrieveEntity(ctx context.Context, req *grpcCommonV1.Retri return res.(*grpcCommonV1.RetrieveEntityRes), nil } -func decodeRetrieveEntityRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRetrieveEntityRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcCommonV1.RetrieveEntityReq) return retrieveEntityReq{ Id: req.GetId(), }, nil } -func encodeRetrieveEntityResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeRetrieveEntityResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(retrieveEntityRes) return &grpcCommonV1.RetrieveEntityRes{ @@ -129,14 +129,14 @@ func (s *grpcServer) RetrieveEntities(ctx context.Context, req *grpcCommonV1.Ret return res.(*grpcCommonV1.RetrieveEntitiesRes), nil } -func decodeRetrieveEntitiesRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRetrieveEntitiesRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcCommonV1.RetrieveEntitiesReq) return retrieveEntitiesReq{ Ids: req.GetIds(), }, nil } -func encodeRetrieveEntitiesResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeRetrieveEntitiesResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(retrieveEntitiesRes) entities := []*grpcCommonV1.EntityBasic{} @@ -159,7 +159,7 @@ func (s *grpcServer) AddConnections(ctx context.Context, req *grpcCommonV1.AddCo return res.(*grpcCommonV1.AddConnectionsRes), nil } -func decodeAddConnectionsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeAddConnectionsRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcCommonV1.AddConnectionsReq) conns := []connection{} @@ -180,7 +180,7 @@ func decodeAddConnectionsRequest(_ context.Context, grpcReq interface{}) (interf }, nil } -func encodeAddConnectionsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeAddConnectionsResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(connectionsRes) return &grpcCommonV1.AddConnectionsRes{Ok: res.ok}, nil @@ -194,7 +194,7 @@ func (s *grpcServer) RemoveConnections(ctx context.Context, req *grpcCommonV1.Re return res.(*grpcCommonV1.RemoveConnectionsRes), nil } -func decodeRemoveConnectionsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRemoveConnectionsRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcCommonV1.RemoveConnectionsReq) conns := []connection{} @@ -215,7 +215,7 @@ func decodeRemoveConnectionsRequest(_ context.Context, grpcReq interface{}) (int }, nil } -func encodeRemoveConnectionsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeRemoveConnectionsResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(connectionsRes) return &grpcCommonV1.RemoveConnectionsRes{Ok: res.ok}, nil @@ -229,7 +229,7 @@ func (s *grpcServer) RemoveChannelConnections(ctx context.Context, req *grpcClie return res.(*grpcClientsV1.RemoveChannelConnectionsRes), nil } -func decodeRemoveChannelConnectionsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRemoveChannelConnectionsRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcClientsV1.RemoveChannelConnectionsReq) return removeChannelConnectionsReq{ @@ -237,7 +237,7 @@ func decodeRemoveChannelConnectionsRequest(_ context.Context, grpcReq interface{ }, nil } -func encodeRemoveChannelConnectionsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeRemoveChannelConnectionsResponse(_ context.Context, grpcRes any) (any, error) { _ = grpcRes.(removeChannelConnectionsRes) return &grpcClientsV1.RemoveChannelConnectionsRes{}, nil } @@ -250,7 +250,7 @@ func (s *grpcServer) UnsetParentGroupFromClient(ctx context.Context, req *grpcCl return res.(*grpcClientsV1.UnsetParentGroupFromClientRes), nil } -func decodeUnsetParentGroupFromClientRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeUnsetParentGroupFromClientRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcClientsV1.UnsetParentGroupFromClientReq) return UnsetParentGroupFromClientReq{ @@ -258,7 +258,7 @@ func decodeUnsetParentGroupFromClientRequest(_ context.Context, grpcReq interfac }, nil } -func encodeUnsetParentGroupFromClientResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeUnsetParentGroupFromClientResponse(_ context.Context, grpcRes any) (any, error) { _ = grpcRes.(UnsetParentGroupFromClientRes) return &grpcClientsV1.UnsetParentGroupFromClientRes{}, nil } diff --git a/clients/api/http/decode.go b/clients/api/http/decode.go index cebc6af58..77ecd32b5 100644 --- a/clients/api/http/decode.go +++ b/clients/api/http/decode.go @@ -18,7 +18,7 @@ import ( const clientID = "clientID" -func decodeViewClient(_ context.Context, r *http.Request) (interface{}, error) { +func decodeViewClient(_ context.Context, r *http.Request) (any, error) { roles, err := apiutil.ReadBoolQuery(r, api.RolesKey, false) if err != nil { return listClientsReq{}, errors.Wrap(apiutil.ErrValidation, err) @@ -32,7 +32,7 @@ func decodeViewClient(_ context.Context, r *http.Request) (interface{}, error) { return req, nil } -func decodeListClients(_ context.Context, r *http.Request) (interface{}, error) { +func decodeListClients(_ context.Context, r *http.Request) (any, error) { name, err := apiutil.ReadStringQuery(r, api.NameKey, "") if err != nil { return listClientsReq{}, errors.Wrap(apiutil.ErrValidation, err) @@ -161,7 +161,7 @@ func decodeListClients(_ context.Context, r *http.Request) (interface{}, error) return req, nil } -func decodeUpdateClient(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateClient(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -176,7 +176,7 @@ func decodeUpdateClient(_ context.Context, r *http.Request) (interface{}, error) return req, nil } -func decodeUpdateClientTags(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateClientTags(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -191,7 +191,7 @@ func decodeUpdateClientTags(_ context.Context, r *http.Request) (interface{}, er return req, nil } -func decodeUpdateClientCredentials(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateClientCredentials(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -206,7 +206,7 @@ func decodeUpdateClientCredentials(_ context.Context, r *http.Request) (interfac return req, nil } -func decodeCreateClientReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeCreateClientReq(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -222,7 +222,7 @@ func decodeCreateClientReq(_ context.Context, r *http.Request) (interface{}, err return req, nil } -func decodeCreateClientsReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeCreateClientsReq(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -235,7 +235,7 @@ func decodeCreateClientsReq(_ context.Context, r *http.Request) (interface{}, er return c, nil } -func decodeChangeClientStatus(_ context.Context, r *http.Request) (interface{}, error) { +func decodeChangeClientStatus(_ context.Context, r *http.Request) (any, error) { req := changeClientStatusReq{ id: chi.URLParam(r, clientID), } @@ -243,7 +243,7 @@ func decodeChangeClientStatus(_ context.Context, r *http.Request) (interface{}, return req, nil } -func decodeSetClientParentGroupStatus(_ context.Context, r *http.Request) (interface{}, error) { +func decodeSetClientParentGroupStatus(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -257,7 +257,7 @@ func decodeSetClientParentGroupStatus(_ context.Context, r *http.Request) (inter return req, nil } -func decodeRemoveClientParentGroupStatus(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRemoveClientParentGroupStatus(_ context.Context, r *http.Request) (any, error) { req := removeClientParentGroupReq{ id: chi.URLParam(r, clientID), } @@ -265,7 +265,7 @@ func decodeRemoveClientParentGroupStatus(_ context.Context, r *http.Request) (in return req, nil } -func decodeDeleteClientReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeDeleteClientReq(_ context.Context, r *http.Request) (any, error) { req := deleteClientReq{ id: chi.URLParam(r, clientID), } diff --git a/clients/api/http/endpoints.go b/clients/api/http/endpoints.go index b472068e6..64b75ee3a 100644 --- a/clients/api/http/endpoints.go +++ b/clients/api/http/endpoints.go @@ -16,7 +16,7 @@ import ( ) func createClientEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(createClientReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -40,7 +40,7 @@ func createClientEndpoint(svc clients.Service) endpoint.Endpoint { } func createClientsEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(createClientsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -71,7 +71,7 @@ func createClientsEndpoint(svc clients.Service) endpoint.Endpoint { } func viewClientEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(viewClientReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -92,7 +92,7 @@ func viewClientEndpoint(svc clients.Service) endpoint.Endpoint { } func listClientsEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listClientsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -132,7 +132,7 @@ func listClientsEndpoint(svc clients.Service) endpoint.Endpoint { } func updateClientEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateClientReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -158,7 +158,7 @@ func updateClientEndpoint(svc clients.Service) endpoint.Endpoint { } func updateClientTagsEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateClientTagsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -183,7 +183,7 @@ func updateClientTagsEndpoint(svc clients.Service) endpoint.Endpoint { } func updateClientSecretEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateClientCredentialsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -204,7 +204,7 @@ func updateClientSecretEndpoint(svc clients.Service) endpoint.Endpoint { } func enableClientEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(changeClientStatusReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -225,7 +225,7 @@ func enableClientEndpoint(svc clients.Service) endpoint.Endpoint { } func disableClientEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(changeClientStatusReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -246,7 +246,7 @@ func disableClientEndpoint(svc clients.Service) endpoint.Endpoint { } func setClientParentGroupEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(setClientParentGroupReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -265,7 +265,7 @@ func setClientParentGroupEndpoint(svc clients.Service) endpoint.Endpoint { } func removeClientParentGroupEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(removeClientParentGroupReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -284,7 +284,7 @@ func removeClientParentGroupEndpoint(svc clients.Service) endpoint.Endpoint { } func deleteClientEndpoint(svc clients.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(deleteClientReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) diff --git a/clients/api/http/endpoints_test.go b/clients/api/http/endpoints_test.go index 26786cbf3..41976c520 100644 --- a/clients/api/http/endpoints_test.go +++ b/clients/api/http/endpoints_test.go @@ -81,7 +81,7 @@ func (tr testRequest) make() (*http.Response, error) { return tr.client.Do(req) } -func toJSON(data interface{}) string { +func toJSON(data any) string { jsonData, err := json.Marshal(data) if err != nil { return "" @@ -169,7 +169,7 @@ func TestCreateClient(t *testing.T) { Identity: "user@example.com", Secret: "12345678", }, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, @@ -361,7 +361,7 @@ func TestCreateClients(t *testing.T) { Identity: "user@example.com", Secret: "12345678", }, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, diff --git a/clients/api/http/requests.go b/clients/api/http/requests.go index 14fa0c7f8..d42e20616 100644 --- a/clients/api/http/requests.go +++ b/clients/api/http/requests.go @@ -113,9 +113,9 @@ func (req listMembersReq) validate() error { type updateClientReq struct { id string - Name string `json:"name,omitempty"` - Metadata map[string]interface{} `json:"metadata,omitempty"` - Tags []string `json:"tags,omitempty"` + Name string `json:"name,omitempty"` + Metadata map[string]any `json:"metadata,omitempty"` + Tags []string `json:"tags,omitempty"` } func (req updateClientReq) validate() error { diff --git a/clients/clients.go b/clients/clients.go index 41a065be3..be9c1031b 100644 --- a/clients/clients.go +++ b/clients/clients.go @@ -221,7 +221,7 @@ type Page struct { } // Metadata represents arbitrary JSON. -type Metadata map[string]interface{} +type Metadata map[string]any // Credentials represent client credentials: its // "identity" which can be a username, email, generated name; diff --git a/clients/events/events.go b/clients/events/events.go index 358c77ceb..7510b5e83 100644 --- a/clients/events/events.go +++ b/clients/events/events.go @@ -53,8 +53,8 @@ type createClientEvent struct { requestID string } -func (cce createClientEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (cce createClientEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": clientCreate, "id": cce.ID, "roles_provisioned": cce.rolesProvisioned, @@ -90,8 +90,8 @@ type updateClientEvent struct { requestID string } -func (uce updateClientEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (uce updateClientEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": uce.operation, "updated_at": uce.UpdatedAt, "updated_by": uce.UpdatedBy, @@ -136,8 +136,8 @@ type changeClientStatusEvent struct { requestID string } -func (cse changeClientStatusEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (cse changeClientStatusEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": cse.operation, "id": cse.id, "status": cse.status, @@ -157,8 +157,8 @@ type viewClientEvent struct { requestID string } -func (vce viewClientEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (vce viewClientEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": clientView, "id": vce.ID, "domain": vce.DomainID, @@ -202,8 +202,8 @@ type viewClientPermsEvent struct { requestID string } -func (vcpe viewClientPermsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (vcpe viewClientPermsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": clientViewPerms, "permissions": vcpe.permissions, "domain": vcpe.DomainID, @@ -221,8 +221,8 @@ type listClientEvent struct { requestID string } -func (lce listClientEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (lce listClientEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": clientList, "total": lce.Total, "offset": lce.Offset, @@ -268,8 +268,8 @@ type listUserClientEvent struct { requestID string } -func (lce listUserClientEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (lce listUserClientEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": clientList, "req_user_id": lce.userID, "total": lce.Total, @@ -317,8 +317,8 @@ type listClientByGroupEvent struct { requestID string } -func (lcge listClientByGroupEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (lcge listClientByGroupEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": clientListByGroup, "total": lcge.Total, "offset": lcge.Offset, @@ -362,8 +362,8 @@ type identifyClientEvent struct { requestID string } -func (ice identifyClientEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (ice identifyClientEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": clientIdentify, "id": ice.clientID, "domain": ice.DomainID, @@ -382,8 +382,8 @@ type authorizeClientEvent struct { requestID string } -func (ice authorizeClientEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (ice authorizeClientEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": clientAuthorize, "id": ice.clientID, "domain": ice.DomainID, @@ -412,8 +412,8 @@ type shareClientEvent struct { requestID string } -func (sce shareClientEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (sce shareClientEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": clientPrefix + sce.action, "id": sce.id, "relation": sce.relation, @@ -432,8 +432,8 @@ type removeClientEvent struct { requestID string } -func (dce removeClientEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (dce removeClientEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": clientRemove, "id": dce.id, "domain": dce.DomainID, @@ -451,8 +451,8 @@ type setParentGroupEvent struct { requestID string } -func (spge setParentGroupEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (spge setParentGroupEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": clientSetParent, "id": spge.id, "parent_group_id": spge.parentGroupID, @@ -470,8 +470,8 @@ type removeParentGroupEvent struct { requestID string } -func (rpge removeParentGroupEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (rpge removeParentGroupEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": clientRemoveParent, "id": rpge.id, "domain": rpge.DomainID, diff --git a/clients/middleware/authorization.go b/clients/middleware/authorization.go index d6fa19e9e..b760c42c0 100644 --- a/clients/middleware/authorization.go +++ b/clients/middleware/authorization.go @@ -564,7 +564,7 @@ func (am *authorizationMiddleware) checkSuperAdmin(ctx context.Context, userID s return nil } -func (am *authorizationMiddleware) callOut(ctx context.Context, session authn.Session, op string, params map[string]interface{}) error { +func (am *authorizationMiddleware) callOut(ctx context.Context, session authn.Session, op string, params map[string]any) error { pl := map[string]any{ "entity_type": policies.ClientType, "subject_type": policies.UserType, diff --git a/clients/postgres/clients.go b/clients/postgres/clients.go index 48819ee56..1ba63c6f4 100644 --- a/clients/postgres/clients.go +++ b/clients/postgres/clients.go @@ -359,7 +359,7 @@ func (repo *clientRepo) RetrieveByIDWithRoles(ctx context.Context, id, memberID FROM clients c2 JOIN final_roles fr ON fr.client_id = c2.id ` - parameters := map[string]interface{}{ + parameters := map[string]any{ "id": id, "member_id": memberID, } @@ -1009,7 +1009,7 @@ func (repo *clientRepo) update(ctx context.Context, client clients.Client, query func (repo *clientRepo) Delete(ctx context.Context, clientIDs ...string) error { q := "DELETE FROM clients AS c WHERE c.id = ANY(:client_ids) ;" - params := map[string]interface{}{ + params := map[string]any{ "client_ids": clientIDs, } result, err := repo.DB.NamedExecContext(ctx, q, params) diff --git a/clients/postgres/clients_test.go b/clients/postgres/clients_test.go index 12e516e81..6b379d1d8 100644 --- a/clients/postgres/clients_test.go +++ b/clients/postgres/clients_test.go @@ -40,7 +40,7 @@ var ( ID: testsutil.GenerateUUID(&testing.T{}), Domain: testsutil.GenerateUUID(&testing.T{}), Name: namegen.Generate(), - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: clients.EnabledStatus, } @@ -311,7 +311,7 @@ func TestClientsSave(t *testing.T) { Identity: fmt.Sprintf("%s@example.com", namegen.Generate()), Secret: testsutil.GenerateUUID(t), }, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, }, @@ -325,7 +325,7 @@ func TestClientsSave(t *testing.T) { ID: duplicateClientID, Domain: validClient.Domain, Name: validClient.Name, - Metadata: map[string]interface{}{"key": "different_value"}, + Metadata: map[string]any{"key": "different_value"}, CreatedAt: validTimestamp, Status: clients.EnabledStatus, }, @@ -519,7 +519,7 @@ func TestUpdate(t *testing.T) { client: clients.Client{ ID: validClient.ID, Name: namegen.Generate(), - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -541,7 +541,7 @@ func TestUpdate(t *testing.T) { update: "metadata", client: clients.Client{ ID: validClient.ID, - Metadata: map[string]interface{}{"key1": "value1"}, + Metadata: map[string]any{"key1": "value1"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -553,7 +553,7 @@ func TestUpdate(t *testing.T) { client: clients.Client{ ID: testsutil.GenerateUUID(t), Name: namegen.Generate(), - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -564,7 +564,7 @@ func TestUpdate(t *testing.T) { update: "all", client: clients.Client{ Name: namegen.Generate(), - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -1734,7 +1734,7 @@ func TestRetrieveByIDs(t *testing.T) { Secret: testsutil.GenerateUUID(t), }, Tags: namegen.GenerateMultiple(5), - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: clients.EnabledStatus, } @@ -2364,7 +2364,7 @@ func TestRetrieveParentGroupClients(t *testing.T) { Domain: testsutil.GenerateUUID(t), ParentGroup: parentID, Name: name, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: clients.EnabledStatus, } @@ -2431,7 +2431,7 @@ func TestUnsetParentGroupFromClients(t *testing.T) { Domain: testsutil.GenerateUUID(t), ParentGroup: parentID, Name: name, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: clients.EnabledStatus, } diff --git a/consumers/consumer.go b/consumers/consumer.go index 403f9a3fe..41b7df59b 100644 --- a/consumers/consumer.go +++ b/consumers/consumer.go @@ -10,7 +10,7 @@ import "context" // to broker, sending notifications, or any other asynchronous job. type AsyncConsumer interface { // ConsumeAsync method is used to asynchronously consume received messages. - ConsumeAsync(ctx context.Context, messages interface{}) + ConsumeAsync(ctx context.Context, messages any) // Errors method returns a channel for reading errors which occur during async writes. // Must be called before performing any writes for errors to be collected. @@ -26,5 +26,5 @@ type AsyncConsumer interface { type BlockingConsumer interface { // ConsumeBlocking method is used to consume received messages synchronously. // A non-nil error is returned to indicate operation failure. - ConsumeBlocking(ctx context.Context, messages interface{}) error + ConsumeBlocking(ctx context.Context, messages any) error } diff --git a/consumers/messages.go b/consumers/messages.go index a60996698..0b5bcfd43 100644 --- a/consumers/messages.go +++ b/consumers/messages.go @@ -33,7 +33,7 @@ var ( // Start method starts consuming messages received from Message broker. // This method transforms messages to SenML format before // using MessageRepository to store them. -func Start(ctx context.Context, id string, sub messaging.Subscriber, consumer interface{}, configPath string, logger *slog.Logger) error { +func Start(ctx context.Context, id string, sub messaging.Subscriber, consumer any, configPath string, logger *slog.Logger) error { cfg, err := loadConfig(configPath) if err != nil { logger.Warn(fmt.Sprintf("Failed to load consumer config: %s", err)) @@ -67,7 +67,7 @@ func Start(ctx context.Context, id string, sub messaging.Subscriber, consumer in func handleSync(ctx context.Context, t transformers.Transformer, sc BlockingConsumer) handleFunc { return func(msg *messaging.Message) error { - m := interface{}(msg) + m := any(msg) var err error if t != nil { m, err = t.Transform(msg) @@ -81,7 +81,7 @@ func handleSync(ctx context.Context, t transformers.Transformer, sc BlockingCons func handleAsync(ctx context.Context, t transformers.Transformer, ac AsyncConsumer) handleFunc { return func(msg *messaging.Message) error { - m := interface{}(msg) + m := any(msg) var err error if t != nil { m, err = t.Transform(msg) diff --git a/domains/api/grpc/client.go b/domains/api/grpc/client.go index cb8fa11ba..9f81d0f59 100644 --- a/domains/api/grpc/client.go +++ b/domains/api/grpc/client.go @@ -72,12 +72,12 @@ func (client domainsGrpcClient) DeleteUserFromDomains(ctx context.Context, in *g return &grpcDomainsV1.DeleteUserRes{Deleted: dpr.deleted}, nil } -func decodeDeleteUserResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeDeleteUserResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcDomainsV1.DeleteUserRes) return deleteUserRes{deleted: res.GetDeleted()}, nil } -func encodeDeleteUserRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeDeleteUserRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(deleteUserPoliciesReq) return &grpcDomainsV1.DeleteUserReq{ Id: req.ID, @@ -103,12 +103,12 @@ func (client domainsGrpcClient) RetrieveStatus(ctx context.Context, in *grpcComm }, nil } -func decodeRetrieveStatusResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRetrieveStatusResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcCommonV1.RetrieveEntityRes) return retrieveStatusRes{status: uint8(res.Entity.GetStatus())}, nil } -func encodeRetrieveStatusRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRetrieveStatusRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(retrieveStatusReq) return &grpcCommonV1.RetrieveEntityReq{ Id: req.ID, @@ -134,12 +134,12 @@ func (client domainsGrpcClient) RetrieveIDByRoute(ctx context.Context, in *grpcC }, nil } -func decodeRetrieveIDByRouteResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRetrieveIDByRouteResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(*grpcCommonV1.RetrieveEntityRes) return retrieveIDByRouteRes{id: res.Entity.GetId()}, nil } -func encodeRetrieveIDByRouteRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRetrieveIDByRouteRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(retrieveIDByRouteReq) return &grpcCommonV1.RetrieveIDByRouteReq{ Route: req.Route, diff --git a/domains/api/grpc/endpoint.go b/domains/api/grpc/endpoint.go index 79918cdac..881d856d2 100644 --- a/domains/api/grpc/endpoint.go +++ b/domains/api/grpc/endpoint.go @@ -11,7 +11,7 @@ import ( ) func deleteUserFromDomainsEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(deleteUserPoliciesReq) if err := req.validate(); err != nil { return deleteUserRes{}, err @@ -26,7 +26,7 @@ func deleteUserFromDomainsEndpoint(svc domains.Service) endpoint.Endpoint { } func retrieveStatusEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveStatusReq) if err := req.validate(); err != nil { return retrieveStatusRes{}, err @@ -44,7 +44,7 @@ func retrieveStatusEndpoint(svc domains.Service) endpoint.Endpoint { } func retrieveIDByRouteEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveIDByRouteReq) if err := req.validate(); err != nil { return retrieveIDByRouteRes{}, err diff --git a/domains/api/grpc/server.go b/domains/api/grpc/server.go index 61f4be57e..bd819af42 100644 --- a/domains/api/grpc/server.go +++ b/domains/api/grpc/server.go @@ -42,14 +42,14 @@ func NewDomainsServer(svc domains.Service) grpcDomainsV1.DomainsServiceServer { } } -func decodeDeleteUserRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeDeleteUserRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcDomainsV1.DeleteUserReq) return deleteUserPoliciesReq{ ID: req.GetId(), }, nil } -func encodeDeleteUserResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeDeleteUserResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(deleteUserRes) return &grpcDomainsV1.DeleteUserRes{Deleted: res.deleted}, nil } @@ -62,7 +62,7 @@ func (s *domainsGrpcServer) DeleteUserFromDomains(ctx context.Context, req *grpc return res.(*grpcDomainsV1.DeleteUserRes), nil } -func decodeRetrieveStatusRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRetrieveStatusRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcCommonV1.RetrieveEntityReq) return retrieveStatusReq{ @@ -70,7 +70,7 @@ func decodeRetrieveStatusRequest(_ context.Context, grpcReq interface{}) (interf }, nil } -func encodeRetrieveStatusResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeRetrieveStatusResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(retrieveStatusRes) return &grpcCommonV1.RetrieveEntityRes{ @@ -89,7 +89,7 @@ func (s *domainsGrpcServer) RetrieveStatus(ctx context.Context, req *grpcCommonV return res.(*grpcCommonV1.RetrieveEntityRes), nil } -func decodeRetrieveIDByRouteRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRetrieveIDByRouteRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcCommonV1.RetrieveIDByRouteReq) return retrieveIDByRouteReq{ @@ -97,7 +97,7 @@ func decodeRetrieveIDByRouteRequest(_ context.Context, grpcReq interface{}) (int }, nil } -func encodeRetrieveIDByRouteResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeRetrieveIDByRouteResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(retrieveIDByRouteRes) return &grpcCommonV1.RetrieveEntityRes{ diff --git a/domains/api/http/decode.go b/domains/api/http/decode.go index bafd1901b..f32b5cc09 100644 --- a/domains/api/http/decode.go +++ b/domains/api/http/decode.go @@ -25,7 +25,7 @@ const ( stateKey = "state" ) -func decodeCreateDomainRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeCreateDomainRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -37,7 +37,7 @@ func decodeCreateDomainRequest(_ context.Context, r *http.Request) (interface{}, return req, nil } -func decodeRetrieveDomainRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRetrieveDomainRequest(_ context.Context, r *http.Request) (any, error) { roles, err := apiutil.ReadBoolQuery(r, api.RolesKey, false) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -49,7 +49,7 @@ func decodeRetrieveDomainRequest(_ context.Context, r *http.Request) (interface{ return req, nil } -func decodeUpdateDomainRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateDomainRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -65,7 +65,7 @@ func decodeUpdateDomainRequest(_ context.Context, r *http.Request) (interface{}, return req, nil } -func decodeListDomainRequest(ctx context.Context, r *http.Request) (interface{}, error) { +func decodeListDomainRequest(ctx context.Context, r *http.Request) (any, error) { page, err := decodePageRequest(ctx, r) if err != nil { return nil, err @@ -77,21 +77,21 @@ func decodeListDomainRequest(ctx context.Context, r *http.Request) (interface{}, return req, nil } -func decodeEnableDomainRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeEnableDomainRequest(_ context.Context, r *http.Request) (any, error) { req := enableDomainReq{ domainID: chi.URLParam(r, "domainID"), } return req, nil } -func decodeDisableDomainRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeDisableDomainRequest(_ context.Context, r *http.Request) (any, error) { req := disableDomainReq{ domainID: chi.URLParam(r, "domainID"), } return req, nil } -func decodeFreezeDomainRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeFreezeDomainRequest(_ context.Context, r *http.Request) (any, error) { req := freezeDomainReq{ domainID: chi.URLParam(r, "domainID"), } @@ -184,7 +184,7 @@ func decodePageRequest(_ context.Context, r *http.Request) (domains.Page, error) }, nil } -func decodeSendInvitationReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeSendInvitationReq(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -197,7 +197,7 @@ func decodeSendInvitationReq(_ context.Context, r *http.Request) (interface{}, e return req, nil } -func decodeListInvitationsReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeListInvitationsReq(_ context.Context, r *http.Request) (any, error) { offset, err := apiutil.ReadNumQuery[uint64](r, api.OffsetKey, api.DefOffset) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -250,7 +250,7 @@ func decodeListInvitationsReq(_ context.Context, r *http.Request) (interface{}, return req, nil } -func decodeAcceptInvitationReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeAcceptInvitationReq(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -263,7 +263,7 @@ func decodeAcceptInvitationReq(_ context.Context, r *http.Request) (interface{}, return req, nil } -func decodeDeleteInvitationReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeDeleteInvitationReq(_ context.Context, r *http.Request) (any, error) { req := deleteInvitationReq{ userID: chi.URLParam(r, "userID"), domainID: chi.URLParam(r, "domainID"), diff --git a/domains/api/http/endpoint.go b/domains/api/http/endpoint.go index 2b6b266a1..cbbc432c4 100644 --- a/domains/api/http/endpoint.go +++ b/domains/api/http/endpoint.go @@ -19,7 +19,7 @@ import ( const InvitationSent = "invitation sent" func createDomainEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(createDomainReq) if err := req.validate(); err != nil { return nil, err @@ -47,7 +47,7 @@ func createDomainEndpoint(svc domains.Service) endpoint.Endpoint { } func retrieveDomainEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveDomainRequest) if err := req.validate(); err != nil { return nil, err @@ -67,7 +67,7 @@ func retrieveDomainEndpoint(svc domains.Service) endpoint.Endpoint { } func updateDomainEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateDomainReq) if err := req.validate(); err != nil { return nil, err @@ -97,7 +97,7 @@ func updateDomainEndpoint(svc domains.Service) endpoint.Endpoint { } func listDomainsEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listDomainsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -117,7 +117,7 @@ func listDomainsEndpoint(svc domains.Service) endpoint.Endpoint { } func enableDomainEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(enableDomainReq) if err := req.validate(); err != nil { return nil, err @@ -136,7 +136,7 @@ func enableDomainEndpoint(svc domains.Service) endpoint.Endpoint { } func disableDomainEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(disableDomainReq) if err := req.validate(); err != nil { return nil, err @@ -155,7 +155,7 @@ func disableDomainEndpoint(svc domains.Service) endpoint.Endpoint { } func freezeDomainEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(freezeDomainReq) if err := req.validate(); err != nil { return nil, err @@ -174,7 +174,7 @@ func freezeDomainEndpoint(svc domains.Service) endpoint.Endpoint { } func sendInvitationEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(sendInvitationReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -202,7 +202,7 @@ func sendInvitationEndpoint(svc domains.Service) endpoint.Endpoint { } func listDomainInvitationsEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listInvitationsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -225,7 +225,7 @@ func listDomainInvitationsEndpoint(svc domains.Service) endpoint.Endpoint { } func listUserInvitationsEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listInvitationsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -248,7 +248,7 @@ func listUserInvitationsEndpoint(svc domains.Service) endpoint.Endpoint { } func acceptInvitationEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(acceptInvitationReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -268,7 +268,7 @@ func acceptInvitationEndpoint(svc domains.Service) endpoint.Endpoint { } func rejectInvitationEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(acceptInvitationReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -288,7 +288,7 @@ func rejectInvitationEndpoint(svc domains.Service) endpoint.Endpoint { } func deleteInvitationEndpoint(svc domains.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(deleteInvitationReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) diff --git a/domains/api/http/endpoint_test.go b/domains/api/http/endpoint_test.go index 03cd764cf..aee6e880a 100644 --- a/domains/api/http/endpoint_test.go +++ b/domains/api/http/endpoint_test.go @@ -84,7 +84,7 @@ func (tr testRequest) make() (*http.Response, error) { return tr.client.Do(req) } -func toJSON(data interface{}) string { +func toJSON(data any) string { jsonData, err := json.Marshal(data) if err != nil { return "" @@ -200,7 +200,7 @@ func TestCreateDomain(t *testing.T) { desc: "register a new domain that cant be marshalled", domain: domains.Domain{ Name: "test", - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, Tags: []string{"tag1", "tag2"}, diff --git a/domains/api/http/requests.go b/domains/api/http/requests.go index f558e14fa..e517f2604 100644 --- a/domains/api/http/requests.go +++ b/domains/api/http/requests.go @@ -12,11 +12,11 @@ import ( const maxLimitSize = 100 type createDomainReq struct { - ID string `json:"id,omitempty"` - Name string `json:"name"` - Metadata map[string]interface{} `json:"metadata,omitempty"` - Tags []string `json:"tags,omitempty"` - Route string `json:"route"` + ID string `json:"id,omitempty"` + Name string `json:"name"` + Metadata map[string]any `json:"metadata,omitempty"` + Tags []string `json:"tags,omitempty"` + Route string `json:"route"` } func (req createDomainReq) validate() error { @@ -51,9 +51,9 @@ func (req retrieveDomainRequest) validate() error { type updateDomainReq struct { domainID string - Name *string `json:"name,omitempty"` - Metadata *map[string]interface{} `json:"metadata,omitempty"` - Tags *[]string `json:"tags,omitempty"` + Name *string `json:"name,omitempty"` + Metadata *map[string]any `json:"metadata,omitempty"` + Tags *[]string `json:"tags,omitempty"` } func (req updateDomainReq) validate() error { diff --git a/domains/domains.go b/domains/domains.go index a78df4ae3..186314dbe 100644 --- a/domains/domains.go +++ b/domains/domains.go @@ -94,7 +94,7 @@ func (s *Status) UnmarshalJSON(data []byte) error { } // Metadata represents arbitrary JSON. -type Metadata map[string]interface{} +type Metadata map[string]any type DomainReq struct { Name *string `json:"name,omitempty"` diff --git a/domains/events/events.go b/domains/events/events.go index 40be85cd5..52f1b9760 100644 --- a/domains/events/events.go +++ b/domains/events/events.go @@ -54,8 +54,8 @@ type createDomainEvent struct { requestID string } -func (cde createDomainEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (cde createDomainEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": domainCreate, "id": cde.ID, "route": cde.Route, @@ -88,8 +88,8 @@ type retrieveDomainEvent struct { requestID string } -func (rde retrieveDomainEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rde retrieveDomainEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": domainRetrieve, "id": rde.ID, "route": rde.Route, @@ -127,8 +127,8 @@ type retrieveDomainStatusEvent struct { requestID string } -func (rdse retrieveDomainStatusEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rdse retrieveDomainStatusEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": domainRetrieve, "id": rdse.id, "status": rdse.status.String(), @@ -147,8 +147,8 @@ type updateDomainEvent struct { requestID string } -func (ude updateDomainEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (ude updateDomainEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": domainUpdate, "id": ude.domain.ID, "route": ude.domain.Route, @@ -184,8 +184,8 @@ type enableDomainEvent struct { requestID string } -func (cdse enableDomainEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (cdse enableDomainEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": domainEnable, "id": cdse.domainID, "updated_at": cdse.updatedAt, @@ -205,8 +205,8 @@ type disableDomainEvent struct { requestID string } -func (cdse disableDomainEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (cdse disableDomainEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": domainDisable, "id": cdse.domainID, "updated_at": cdse.updatedAt, @@ -226,8 +226,8 @@ type freezeDomainEvent struct { requestID string } -func (cdse freezeDomainEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (cdse freezeDomainEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": domainFreeze, "id": cdse.domainID, "updated_at": cdse.updatedAt, @@ -248,8 +248,8 @@ type listDomainsEvent struct { requestID string } -func (lde listDomainsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (lde listDomainsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": domainList, "total": lde.total, "offset": lde.Offset, @@ -308,8 +308,8 @@ type sendInvitationEvent struct { session authn.Session } -func (sie sendInvitationEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (sie sendInvitationEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": invitationSend, "invitee_user_id": sie.invitation.InviteeUserID, "domain_id": sie.invitation.DomainID, @@ -327,8 +327,8 @@ type listInvitationsEvent struct { session authn.Session } -func (lie listInvitationsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (lie listInvitationsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": invitationList, "offset": lie.Offset, "limit": lie.Limit, @@ -360,8 +360,8 @@ type listDomainInvitationsEvent struct { session authn.Session } -func (lie listDomainInvitationsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (lie listDomainInvitationsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": invitationListDomain, "offset": lie.Offset, "limit": lie.Limit, @@ -391,8 +391,8 @@ type acceptInvitationEvent struct { session authn.Session } -func (aie acceptInvitationEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (aie acceptInvitationEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": invitationAccept, "domain_id": aie.domainID, "invitee_user_id": aie.session.UserID, @@ -408,8 +408,8 @@ type rejectInvitationEvent struct { session authn.Session } -func (rie rejectInvitationEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rie rejectInvitationEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": invitationReject, "domain_id": rie.domainID, "invitee_user_id": rie.session.UserID, @@ -426,8 +426,8 @@ type deleteInvitationEvent struct { session authn.Session } -func (die deleteInvitationEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (die deleteInvitationEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": invitationDelete, "invitee_user_id": die.inviteeUserID, "domain_id": die.domainID, diff --git a/domains/middleware/authorization.go b/domains/middleware/authorization.go index d68f10331..1fea9d12e 100644 --- a/domains/middleware/authorization.go +++ b/domains/middleware/authorization.go @@ -342,7 +342,7 @@ func (am *authorizationMiddleware) extAuthorize(ctx context.Context, subj, perm, return nil } -func (am *authorizationMiddleware) callOut(ctx context.Context, session authn.Session, op string, params map[string]interface{}) error { +func (am *authorizationMiddleware) callOut(ctx context.Context, session authn.Session, op string, params map[string]any) error { pl := map[string]any{ "entity_type": policies.DomainType, "subject_type": policies.UserType, diff --git a/domains/postgres/domains_test.go b/domains/postgres/domains_test.go index e3f05c601..9dbea9b8e 100644 --- a/domains/postgres/domains_test.go +++ b/domains/postgres/domains_test.go @@ -45,7 +45,7 @@ func TestSaveDomain(t *testing.T) { Name: "test", Route: "test", Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedAt: time.Now().UTC().Truncate(time.Millisecond), @@ -63,7 +63,7 @@ func TestSaveDomain(t *testing.T) { Name: "test", Route: "test", Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedAt: time.Now().UTC().Truncate(time.Millisecond), @@ -81,7 +81,7 @@ func TestSaveDomain(t *testing.T) { Name: "test1", Route: "test1", Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedAt: time.Now().UTC().Truncate(time.Millisecond), @@ -99,7 +99,7 @@ func TestSaveDomain(t *testing.T) { Name: "test1", Route: "", Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedAt: time.Now(), @@ -117,7 +117,7 @@ func TestSaveDomain(t *testing.T) { Name: "test1", Route: "test1", Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, CreatedAt: time.Now(), @@ -154,7 +154,7 @@ func TestRetrieveByID(t *testing.T) { Name: "test", Route: "test", Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedBy: userID, @@ -216,7 +216,7 @@ func TestRetrieveByRoute(t *testing.T) { Name: "test", Route: validRoute, Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedBy: userID, @@ -279,7 +279,7 @@ func TestRetrieveAllByIDs(t *testing.T) { Name: fmt.Sprintf(`"test%d"`, i), Route: fmt.Sprintf(`"test%d"`, i), Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedBy: userID, @@ -289,7 +289,7 @@ func TestRetrieveAllByIDs(t *testing.T) { if i%5 == 0 { domain.Status = domains.DisabledStatus domain.Tags = []string{"test", "admin"} - domain.Metadata = map[string]interface{}{ + domain.Metadata = map[string]any{ "test1": "test1", } } @@ -398,7 +398,7 @@ func TestRetrieveAllByIDs(t *testing.T) { Offset: 0, Limit: 10, IDs: []string{items[1].ID, items[2].ID}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, Status: domains.EnabledStatus, @@ -416,7 +416,7 @@ func TestRetrieveAllByIDs(t *testing.T) { Offset: 0, Limit: 10, IDs: []string{items[1].ID, items[2].ID}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test1": "test1", }, Status: domains.EnabledStatus, @@ -433,7 +433,7 @@ func TestRetrieveAllByIDs(t *testing.T) { Offset: 0, Limit: 10, IDs: []string{items[1].ID, items[2].ID}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, Status: domains.EnabledStatus, @@ -521,7 +521,7 @@ func TestUpdate(t *testing.T) { Name: "test", Route: "test", Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedBy: userID, @@ -551,7 +551,7 @@ func TestUpdate(t *testing.T) { Name: "test1", Route: "test", Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test1": "test1", }, CreatedBy: userID, @@ -575,7 +575,7 @@ func TestUpdate(t *testing.T) { Name: "test1", Route: "test", Tags: []string{"test1"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test1": "test1", }, CreatedBy: userID, @@ -640,7 +640,7 @@ func TestDelete(t *testing.T) { Name: "test", Route: "test", Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedBy: userID, @@ -696,7 +696,7 @@ func TestListDomains(t *testing.T) { Name: fmt.Sprintf(`"test%d"`, i), Route: fmt.Sprintf(`"test%d"`, i), Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedBy: userID, @@ -706,7 +706,7 @@ func TestListDomains(t *testing.T) { if i%5 == 0 { domain.Status = domains.DisabledStatus domain.Tags = []string{"test", "admin"} - domain.Metadata = map[string]interface{}{ + domain.Metadata = map[string]any{ "test1": "test1", } } @@ -818,7 +818,7 @@ func TestListDomains(t *testing.T) { pm: domains.Page{ Offset: 0, Limit: 10, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test1": "test1", }, Status: domains.AllStatus, @@ -836,7 +836,7 @@ func TestListDomains(t *testing.T) { pm: domains.Page{ Offset: 0, Limit: 10, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, Status: domains.AllStatus, diff --git a/domains/postgres/invitations_test.go b/domains/postgres/invitations_test.go index c9d0957bd..77a7804fa 100644 --- a/domains/postgres/invitations_test.go +++ b/domains/postgres/invitations_test.go @@ -825,7 +825,7 @@ func saveDomain(t *testing.T, repo domains.Repository) domains.Domain { Name: "test", Route: "test", Tags: []string{"test"}, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": "test", }, CreatedBy: userID, diff --git a/groups/api/grpc/client.go b/groups/api/grpc/client.go index 1cb6206e4..91b1bbb31 100644 --- a/groups/api/grpc/client.go +++ b/groups/api/grpc/client.go @@ -57,11 +57,11 @@ func (client grpcClient) RetrieveEntity(ctx context.Context, req *grpcCommonV1.R return typedRes, nil } -func encodeRetrieveEntityRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func encodeRetrieveEntityRequest(_ context.Context, grpcReq any) (any, error) { return grpcReq, nil } -func decodeRetrieveEntityResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func decodeRetrieveEntityResponse(_ context.Context, grpcRes any) (any, error) { return grpcRes, nil } diff --git a/groups/api/grpc/endpoint.go b/groups/api/grpc/endpoint.go index 9f3288576..b9fefdfa5 100644 --- a/groups/api/grpc/endpoint.go +++ b/groups/api/grpc/endpoint.go @@ -11,7 +11,7 @@ import ( ) func retrieveEntityEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveEntityReq) group, err := svc.RetrieveById(ctx, req.Id) if err != nil { diff --git a/groups/api/grpc/server.go b/groups/api/grpc/server.go index 451ae939f..6b6f97440 100644 --- a/groups/api/grpc/server.go +++ b/groups/api/grpc/server.go @@ -44,14 +44,14 @@ func (s *grpcServer) RetrieveEntity(ctx context.Context, req *grpcCommonV1.Retri return res.(*grpcCommonV1.RetrieveEntityRes), nil } -func decodeRetrieveEntityRequest(_ context.Context, grpcReq interface{}) (interface{}, error) { +func decodeRetrieveEntityRequest(_ context.Context, grpcReq any) (any, error) { req := grpcReq.(*grpcCommonV1.RetrieveEntityReq) return retrieveEntityReq{ Id: req.GetId(), }, nil } -func encodeRetrieveEntityResponse(_ context.Context, grpcRes interface{}) (interface{}, error) { +func encodeRetrieveEntityResponse(_ context.Context, grpcRes any) (any, error) { res := grpcRes.(retrieveEntityRes) return &grpcCommonV1.RetrieveEntityRes{ diff --git a/groups/api/http/decode.go b/groups/api/http/decode.go index 6f8d82ec6..56c0ad3d5 100644 --- a/groups/api/http/decode.go +++ b/groups/api/http/decode.go @@ -16,7 +16,7 @@ import ( "github.com/go-chi/chi/v5" ) -func DecodeGroupCreate(_ context.Context, r *http.Request) (interface{}, error) { +func DecodeGroupCreate(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -31,7 +31,7 @@ func DecodeGroupCreate(_ context.Context, r *http.Request) (interface{}, error) return req, nil } -func DecodeListGroupsRequest(_ context.Context, r *http.Request) (interface{}, error) { +func DecodeListGroupsRequest(_ context.Context, r *http.Request) (any, error) { pm, err := decodePageMeta(r) if err != nil { return nil, err @@ -55,7 +55,7 @@ func DecodeListGroupsRequest(_ context.Context, r *http.Request) (interface{}, e return req, nil } -func DecodeGroupUpdate(_ context.Context, r *http.Request) (interface{}, error) { +func DecodeGroupUpdate(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -68,7 +68,7 @@ func DecodeGroupUpdate(_ context.Context, r *http.Request) (interface{}, error) return req, nil } -func decodeUpdateGroupTags(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateGroupTags(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -83,7 +83,7 @@ func decodeUpdateGroupTags(_ context.Context, r *http.Request) (interface{}, err return req, nil } -func DecodeGroupRequest(_ context.Context, r *http.Request) (interface{}, error) { +func DecodeGroupRequest(_ context.Context, r *http.Request) (any, error) { roles, err := apiutil.ReadBoolQuery(r, api.RolesKey, false) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -97,14 +97,14 @@ func DecodeGroupRequest(_ context.Context, r *http.Request) (interface{}, error) return req, nil } -func DecodeChangeGroupStatusRequest(_ context.Context, r *http.Request) (interface{}, error) { +func DecodeChangeGroupStatusRequest(_ context.Context, r *http.Request) (any, error) { req := changeGroupStatusReq{ id: chi.URLParam(r, "groupID"), } return req, nil } -func decodeRetrieveGroupHierarchy(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRetrieveGroupHierarchy(_ context.Context, r *http.Request) (any, error) { hm, err := decodeHierarchyPageMeta(r) if err != nil { return nil, err @@ -117,7 +117,7 @@ func decodeRetrieveGroupHierarchy(_ context.Context, r *http.Request) (interface return req, nil } -func decodeAddParentGroupRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeAddParentGroupRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -131,14 +131,14 @@ func decodeAddParentGroupRequest(_ context.Context, r *http.Request) (interface{ return req, nil } -func decodeRemoveParentGroupRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRemoveParentGroupRequest(_ context.Context, r *http.Request) (any, error) { req := removeParentGroupReq{ id: chi.URLParam(r, "groupID"), } return req, nil } -func decodeAddChildrenGroupsRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeAddChildrenGroupsRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -151,7 +151,7 @@ func decodeAddChildrenGroupsRequest(_ context.Context, r *http.Request) (interfa return req, nil } -func decodeRemoveChildrenGroupsRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRemoveChildrenGroupsRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -164,14 +164,14 @@ func decodeRemoveChildrenGroupsRequest(_ context.Context, r *http.Request) (inte return req, nil } -func decodeRemoveAllChildrenGroupsRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRemoveAllChildrenGroupsRequest(_ context.Context, r *http.Request) (any, error) { req := removeAllChildrenGroupsReq{ id: chi.URLParam(r, "groupID"), } return req, nil } -func decodeListChildrenGroupsRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeListChildrenGroupsRequest(_ context.Context, r *http.Request) (any, error) { pm, err := decodePageMeta(r) if err != nil { return nil, err diff --git a/groups/api/http/decode_test.go b/groups/api/http/decode_test.go index e57b79a8c..35d544d4e 100644 --- a/groups/api/http/decode_test.go +++ b/groups/api/http/decode_test.go @@ -23,7 +23,7 @@ func TestDecodeListGroupsRequest(t *testing.T) { desc string url string header map[string][]string - resp interface{} + resp any err error }{ { @@ -89,7 +89,7 @@ func TestDecodeRetrieveGroupHierarchy(t *testing.T) { desc string url string header map[string][]string - resp interface{} + resp any err error }{ { @@ -157,7 +157,7 @@ func TestDecodeListChildrenRequest(t *testing.T) { desc string url string header map[string][]string - resp interface{} + resp any err error }{ { @@ -311,7 +311,7 @@ func TestDecodeGroupCreate(t *testing.T) { desc string body string header map[string][]string - resp interface{} + resp any err error }{ { @@ -366,7 +366,7 @@ func TestDecodeGroupUpdate(t *testing.T) { desc string body string header map[string][]string - resp interface{} + resp any err error }{ { @@ -418,7 +418,7 @@ func TestDecodeGroupRequest(t *testing.T) { cases := []struct { desc string header map[string][]string - resp interface{} + resp any err error }{ { @@ -450,7 +450,7 @@ func TestDecodeChangeGroupStatus(t *testing.T) { cases := []struct { desc string header map[string][]string - resp interface{} + resp any err error }{ { diff --git a/groups/api/http/endpoint_test.go b/groups/api/http/endpoint_test.go index 8ad4e9e54..13a6b8b06 100644 --- a/groups/api/http/endpoint_test.go +++ b/groups/api/http/endpoint_test.go @@ -72,7 +72,7 @@ func TestCreateGroupEndpoint(t *testing.T) { reqGroup := groups.Group{ Name: valid, Description: desc, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, } @@ -144,7 +144,7 @@ func TestCreateGroupEndpoint(t *testing.T) { req: createGroupReq{ Group: groups.Group{ Description: desc, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, }, @@ -161,7 +161,7 @@ func TestCreateGroupEndpoint(t *testing.T) { Group: groups.Group{ Name: strings.Repeat("a", 1025), Description: desc, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, }, @@ -339,7 +339,7 @@ func TestUpdateGroupEndpoint(t *testing.T) { ID: validID, Name: valid, Description: desc, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, } @@ -411,7 +411,7 @@ func TestUpdateGroupEndpoint(t *testing.T) { ID: validID, Name: strings.Repeat("a", 1025), Description: desc, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "name": "test", }, }, @@ -2193,7 +2193,7 @@ func (tr testRequest) make() (*http.Response, error) { return tr.client.Do(req) } -func toJSON(data interface{}) string { +func toJSON(data any) string { jsonData, err := json.Marshal(data) if err != nil { return "" diff --git a/groups/api/http/endpoints.go b/groups/api/http/endpoints.go index 6461113f5..6bb946b19 100644 --- a/groups/api/http/endpoints.go +++ b/groups/api/http/endpoints.go @@ -16,7 +16,7 @@ import ( ) func CreateGroupEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(createGroupReq) if err := req.validate(); err != nil { return createGroupRes{created: false}, errors.Wrap(apiutil.ErrValidation, err) @@ -37,7 +37,7 @@ func CreateGroupEndpoint(svc groups.Service) endpoint.Endpoint { } func ViewGroupEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(groupReq) if err := req.validate(); err != nil { return viewGroupRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -58,7 +58,7 @@ func ViewGroupEndpoint(svc groups.Service) endpoint.Endpoint { } func UpdateGroupEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateGroupReq) if err := req.validate(); err != nil { return updateGroupRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -86,7 +86,7 @@ func UpdateGroupEndpoint(svc groups.Service) endpoint.Endpoint { } func updateGroupTagsEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateGroupTagsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -111,7 +111,7 @@ func updateGroupTagsEndpoint(svc groups.Service) endpoint.Endpoint { } func EnableGroupEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(changeGroupStatusReq) if err := req.validate(); err != nil { return changeStatusRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -131,7 +131,7 @@ func EnableGroupEndpoint(svc groups.Service) endpoint.Endpoint { } func DisableGroupEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(changeGroupStatusReq) if err := req.validate(); err != nil { return changeStatusRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -151,7 +151,7 @@ func DisableGroupEndpoint(svc groups.Service) endpoint.Endpoint { } func ListGroupsEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listGroupsReq) if err := req.validate(); err != nil { @@ -192,7 +192,7 @@ func ListGroupsEndpoint(svc groups.Service) endpoint.Endpoint { } func DeleteGroupEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(groupReq) if err := req.validate(); err != nil { return deleteGroupRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -210,7 +210,7 @@ func DeleteGroupEndpoint(svc groups.Service) endpoint.Endpoint { } func retrieveGroupHierarchyEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveGroupHierarchyReq) if err := req.validate(); err != nil { return retrieveGroupHierarchyRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -238,7 +238,7 @@ func retrieveGroupHierarchyEndpoint(svc groups.Service) endpoint.Endpoint { } func addParentGroupEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(addParentGroupReq) if err := req.validate(); err != nil { return addParentGroupRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -257,7 +257,7 @@ func addParentGroupEndpoint(svc groups.Service) endpoint.Endpoint { } func removeParentGroupEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(removeParentGroupReq) if err := req.validate(); err != nil { return removeParentGroupRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -276,7 +276,7 @@ func removeParentGroupEndpoint(svc groups.Service) endpoint.Endpoint { } func addChildrenGroupsEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(addChildrenGroupsReq) if err := req.validate(); err != nil { return addChildrenGroupsRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -295,7 +295,7 @@ func addChildrenGroupsEndpoint(svc groups.Service) endpoint.Endpoint { } func removeChildrenGroupsEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(removeChildrenGroupsReq) if err := req.validate(); err != nil { return removeChildrenGroupsRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -314,7 +314,7 @@ func removeChildrenGroupsEndpoint(svc groups.Service) endpoint.Endpoint { } func removeAllChildrenGroupsEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(removeAllChildrenGroupsReq) if err := req.validate(); err != nil { return removeAllChildrenGroupsRes{}, errors.Wrap(apiutil.ErrValidation, err) @@ -333,7 +333,7 @@ func removeAllChildrenGroupsEndpoint(svc groups.Service) endpoint.Endpoint { } func listChildrenGroupsEndpoint(svc groups.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listChildrenGroupsReq) if err := req.validate(); err != nil { return listChildrenGroupsRes{}, errors.Wrap(apiutil.ErrValidation, err) diff --git a/groups/api/http/requests.go b/groups/api/http/requests.go index 9172cf96c..6205ea7fc 100644 --- a/groups/api/http/requests.go +++ b/groups/api/http/requests.go @@ -26,7 +26,7 @@ type updateGroupReq struct { id string Name string `json:"name,omitempty"` Description nullable.Value[string] `json:"description,omitempty"` - Metadata map[string]interface{} `json:"metadata,omitempty"` + Metadata map[string]any `json:"metadata,omitempty"` } func (req updateGroupReq) validate() error { diff --git a/groups/events/events.go b/groups/events/events.go index 5d220ce1e..53364f3e7 100644 --- a/groups/events/events.go +++ b/groups/events/events.go @@ -58,8 +58,8 @@ type createGroupEvent struct { requestID string } -func (cge createGroupEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (cge createGroupEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": groupCreate, "id": cge.ID, "roles_provisioned": cge.rolesProvisioned, @@ -98,8 +98,8 @@ type updateGroupEvent struct { requestID string } -func (uge updateGroupEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (uge updateGroupEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": uge.operation, "updated_at": uge.UpdatedAt, "updated_by": uge.UpdatedBy, @@ -146,8 +146,8 @@ type changeGroupStatusEvent struct { requestID string } -func (rge changeGroupStatusEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (rge changeGroupStatusEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": rge.operation, "id": rge.id, "status": rge.status, @@ -167,8 +167,8 @@ type viewGroupEvent struct { requestID string } -func (vge viewGroupEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (vge viewGroupEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": groupView, "id": vge.ID, "domain": vge.DomainID, @@ -215,8 +215,8 @@ type listGroupEvent struct { requestID string } -func (lge listGroupEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (lge listGroupEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": groupList, "total": lge.Total, "offset": lge.Offset, @@ -253,8 +253,8 @@ type listUserGroupEvent struct { requestID string } -func (luge listUserGroupEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (luge listUserGroupEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": groupListUserGroups, "user_id": luge.userID, "domain": luge.domainID, @@ -288,8 +288,8 @@ type deleteGroupEvent struct { requestID string } -func (rge deleteGroupEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (rge deleteGroupEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": groupRemove, "id": rge.id, "domain": rge.DomainID, @@ -307,8 +307,8 @@ type retrieveGroupHierarchyEvent struct { requestID string } -func (vcge retrieveGroupHierarchyEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (vcge retrieveGroupHierarchyEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": groupRetrieveGroupHierarchy, "id": vcge.id, "level": vcge.Level, @@ -330,8 +330,8 @@ type addParentGroupEvent struct { requestID string } -func (apge addParentGroupEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (apge addParentGroupEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": groupAddParentGroup, "id": apge.id, "parent_id": apge.parentID, @@ -349,8 +349,8 @@ type removeParentGroupEvent struct { requestID string } -func (rpge removeParentGroupEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (rpge removeParentGroupEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": groupRemoveParentGroup, "id": rpge.id, "domain": rpge.DomainID, @@ -367,8 +367,8 @@ type viewParentGroupEvent struct { requestID string } -func (vpge viewParentGroupEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (vpge viewParentGroupEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": groupViewParentGroup, "id": vpge.id, "domain": vpge.domainID, @@ -383,8 +383,8 @@ type addChildrenGroupsEvent struct { requestID string } -func (acge addChildrenGroupsEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (acge addChildrenGroupsEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": groupAddChildrenGroups, "id": acge.id, "children_ids": acge.childrenIDs, @@ -403,8 +403,8 @@ type removeChildrenGroupsEvent struct { requestID string } -func (rcge removeChildrenGroupsEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (rcge removeChildrenGroupsEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": groupRemoveChildrenGroups, "id": rcge.id, "children_ids": rcge.childrenIDs, @@ -422,8 +422,8 @@ type removeAllChildrenGroupsEvent struct { requestID string } -func (racge removeAllChildrenGroupsEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (racge removeAllChildrenGroupsEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": groupRemoveAllChildrenGroups, "id": racge.id, "domain": racge.DomainID, @@ -446,8 +446,8 @@ type listChildrenGroupsEvent struct { requestID string } -func (vcge listChildrenGroupsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (vcge listChildrenGroupsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": groupListChildrenGroups, "id": vcge.id, "start_level": vcge.startLevel, diff --git a/groups/groups.go b/groups/groups.go index a52f939df..761f9c6ba 100644 --- a/groups/groups.go +++ b/groups/groups.go @@ -19,7 +19,7 @@ const ( ) // Metadata represents arbitrary JSON. -type Metadata map[string]interface{} +type Metadata map[string]any // Group represents the group of Clients. // Indicates a level in tree hierarchy. Root node is level 1. diff --git a/groups/middleware/authorization.go b/groups/middleware/authorization.go index 7ed6ce8a0..756ff0785 100644 --- a/groups/middleware/authorization.go +++ b/groups/middleware/authorization.go @@ -723,7 +723,7 @@ func (am *authorizationMiddleware) extAuthorize(ctx context.Context, extOp svcut return nil } -func (am *authorizationMiddleware) callOut(ctx context.Context, session authn.Session, op string, params map[string]interface{}) error { +func (am *authorizationMiddleware) callOut(ctx context.Context, session authn.Session, op string, params map[string]any) error { pl := map[string]any{ "entity_type": policies.GroupType, "subject_type": policies.UserType, diff --git a/groups/postgres/groups.go b/groups/postgres/groups.go index ddfd363b5..ee76e65df 100644 --- a/groups/postgres/groups.go +++ b/groups/postgres/groups.go @@ -335,7 +335,7 @@ func (repo groupRepository) RetrieveByIDWithRoles(ctx context.Context, id, membe JOIN final_roles fr ON fr.group_id = g.id ` - parameters := map[string]interface{}{ + parameters := map[string]any{ "id": id, "member_id": memberID, } @@ -549,7 +549,7 @@ func (repo groupRepository) RetrieveHierarchy(ctx context.Context, domainID, use ORDER BY path; `, baseQuery, dirQuery) - parameters := map[string]interface{}{ + parameters := map[string]any{ "id": groupID, "level": hm.Level, } @@ -624,7 +624,7 @@ func (repo groupRepository) AssignParentGroup(ctx context.Context, parentGroupID WHERE id = ANY(:children_group_ids) RETURNING id, path;` - params := map[string]interface{}{ + params := map[string]any{ "parent_id": pGroup.ID, "children_group_ids": groupIDs, } @@ -705,7 +705,7 @@ func (repo groupRepository) UnassignParentGroup(ctx context.Context, parentGroup WHERE id = ANY(:children_group_ids) AND parent_id = :parent_id RETURNING id, path;` - parameters := map[string]interface{}{ + parameters := map[string]any{ "parent_id": pGroup.ID, "children_group_ids": groupIDs, } diff --git a/groups/postgres/groups_test.go b/groups/postgres/groups_test.go index 667cb45cf..9e5d955ba 100644 --- a/groups/postgres/groups_test.go +++ b/groups/postgres/groups_test.go @@ -37,7 +37,7 @@ var ( Name: namegen.Generate(), Tags: []string{"tag1", "tag2"}, Description: desc, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: groups.EnabledStatus, } @@ -121,7 +121,7 @@ func TestSave(t *testing.T) { Domain: testsutil.GenerateUUID(t), Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, }, @@ -134,7 +134,7 @@ func TestSave(t *testing.T) { Domain: invalidID, Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, }, @@ -147,7 +147,7 @@ func TestSave(t *testing.T) { Parent: testsutil.GenerateUUID(t), Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, }, @@ -160,7 +160,7 @@ func TestSave(t *testing.T) { Domain: testsutil.GenerateUUID(t), Name: strings.Repeat("a", 1025), Description: desc, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, }, @@ -173,7 +173,7 @@ func TestSave(t *testing.T) { Domain: testsutil.GenerateUUID(t), Name: namegen.Generate(), Description: invalidDesc, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, }, @@ -186,7 +186,7 @@ func TestSave(t *testing.T) { Domain: testsutil.GenerateUUID(t), Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, CreatedAt: validTimestamp, @@ -201,7 +201,7 @@ func TestSave(t *testing.T) { Name: namegen.Generate(), Domain: invalidID, Description: desc, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, }, @@ -214,7 +214,7 @@ func TestSave(t *testing.T) { Domain: validGroup.Domain, Name: validGroup.Name, Description: desc, - Metadata: map[string]interface{}{"key": "different_value"}, + Metadata: map[string]any{"key": "different_value"}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, Path: duplicateGroupID, @@ -225,7 +225,7 @@ func TestSave(t *testing.T) { Domain: validGroup.Domain, Name: validGroup.Name, Description: desc, - Metadata: map[string]interface{}{"key": "different_value"}, + Metadata: map[string]any{"key": "different_value"}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, Path: duplicateGroupID, @@ -268,7 +268,7 @@ func TestUpdate(t *testing.T) { ID: group.ID, Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -301,7 +301,7 @@ func TestUpdate(t *testing.T) { update: "metadata", group: groups.Group{ ID: group.ID, - Metadata: map[string]interface{}{"key1": "value1"}, + Metadata: map[string]any{"key1": "value1"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -314,7 +314,7 @@ func TestUpdate(t *testing.T) { ID: testsutil.GenerateUUID(t), Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -326,7 +326,7 @@ func TestUpdate(t *testing.T) { group: groups.Group{ Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{"key": "value"}, + Metadata: map[string]any{"key": "value"}, UpdatedAt: validTimestamp, UpdatedBy: testsutil.GenerateUUID(t), }, @@ -554,7 +554,7 @@ func TestRetrieveByIDAndUser(t *testing.T) { Domain: domainID, Name: name, Description: desc, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, } @@ -683,7 +683,7 @@ func TestRetrieveAll(t *testing.T) { Parent: parentID, Name: name, Description: desc, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: groups.EnabledStatus, } @@ -916,7 +916,7 @@ func TestRetrieveAll(t *testing.T) { PageMeta: groups.PageMeta{ Offset: 0, Limit: 10, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, }, @@ -1008,7 +1008,7 @@ func TestRetrieveByIDs(t *testing.T) { Parent: parentID, Name: name, Description: desc, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: groups.EnabledStatus, } @@ -1226,7 +1226,7 @@ func TestRetrieveByIDs(t *testing.T) { PageMeta: groups.PageMeta{ Offset: 0, Limit: 10, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, }, @@ -1319,7 +1319,7 @@ func TestAssignParentGroup(t *testing.T) { Domain: testsutil.GenerateUUID(t), Name: name, Description: desc, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, } @@ -1394,7 +1394,7 @@ func TestUnassignParentGroup(t *testing.T) { Parent: parentID, Name: name, Description: desc, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: groups.EnabledStatus, } @@ -1472,7 +1472,7 @@ func TestUnassignAllChildrenGroups(t *testing.T) { Parent: parentID, Name: name, Description: desc, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: groups.EnabledStatus, } @@ -1536,7 +1536,7 @@ func TestRetrieveHierarchy(t *testing.T) { Parent: parentID, Name: name, Description: desc, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: time.Now().UTC().Truncate(time.Microsecond), Status: groups.EnabledStatus, } @@ -1703,7 +1703,7 @@ func TestRetrieveAllParentGroups(t *testing.T) { Name: name, Parent: parentID, Description: desc, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, } @@ -1880,7 +1880,7 @@ func TestRetrieveChildrenGroups(t *testing.T) { Name: name, Parent: parentID, Description: desc, - Metadata: map[string]interface{}{"name": name}, + Metadata: map[string]any{"name": name}, CreatedAt: validTimestamp, Status: groups.EnabledStatus, } diff --git a/groups/service_test.go b/groups/service_test.go index 9f99d0386..2c10da501 100644 --- a/groups/service_test.go +++ b/groups/service_test.go @@ -41,7 +41,7 @@ var ( ID: testsutil.GenerateUUID(&testing.T{}), Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": "value", }, Status: groups.EnabledStatus, @@ -50,7 +50,7 @@ var ( ID: testsutil.GenerateUUID(&testing.T{}), Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": "value", }, Status: groups.EnabledStatus, @@ -68,7 +68,7 @@ var ( ID: childGroupID, Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": "value", }, Status: groups.EnabledStatus, @@ -79,7 +79,7 @@ var ( ID: parentGroupID, Name: namegen.Generate(), Description: desc, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": "value", }, Status: groups.EnabledStatus, diff --git a/http/api/endpoint.go b/http/api/endpoint.go index c002dc7e3..dc70cbd2e 100644 --- a/http/api/endpoint.go +++ b/http/api/endpoint.go @@ -12,7 +12,7 @@ import ( ) func sendMessageEndpoint() endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(publishReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) diff --git a/http/api/transport.go b/http/api/transport.go index 3ffae9884..1ca1851da 100644 --- a/http/api/transport.go +++ b/http/api/transport.go @@ -53,7 +53,7 @@ func MakeHandler(logger *slog.Logger, instanceID string) http.Handler { return r } -func decodeRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRequest(_ context.Context, r *http.Request) (any, error) { ct := r.Header.Get("Content-Type") if ct != ctSenmlJSON && ct != contentType && ct != ctSenmlCBOR { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) diff --git a/journal/api/endpoint.go b/journal/api/endpoint.go index a8128783b..67cecdee0 100644 --- a/journal/api/endpoint.go +++ b/journal/api/endpoint.go @@ -16,7 +16,7 @@ import ( ) func retrieveJournalsEndpoint(svc journal.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveJournalsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -39,7 +39,7 @@ func retrieveJournalsEndpoint(svc journal.Service) endpoint.Endpoint { } func retrieveClientTelemetryEndpoint(svc journal.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(retrieveClientTelemetryReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) diff --git a/journal/api/transport.go b/journal/api/transport.go index 2b01d82da..a9f34f094 100644 --- a/journal/api/transport.go +++ b/journal/api/transport.go @@ -74,7 +74,7 @@ func MakeHandler(svc journal.Service, authn smqauthn.Authentication, logger *slo return mux } -func decodeRetrieveEntityJournalReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRetrieveEntityJournalReq(_ context.Context, r *http.Request) (any, error) { page, err := decodePageQuery(r) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -94,7 +94,7 @@ func decodeRetrieveEntityJournalReq(_ context.Context, r *http.Request) (interfa return req, nil } -func decodeRetrieveUserJournalReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRetrieveUserJournalReq(_ context.Context, r *http.Request) (any, error) { page, err := decodePageQuery(r) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -170,7 +170,7 @@ func decodePageQuery(r *http.Request) (journal.Page, error) { }, nil } -func decodeRetrieveClientTelemetryReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRetrieveClientTelemetryReq(_ context.Context, r *http.Request) (any, error) { req := retrieveClientTelemetryReq{ clientID: chi.URLParam(r, "clientID"), } diff --git a/journal/events/consumer.go b/journal/events/consumer.go index 817db8429..100600b13 100644 --- a/journal/events/consumer.go +++ b/journal/events/consumer.go @@ -64,9 +64,9 @@ func Handle(service journal.Service) handleFunc { return nil } - metadata, ok := data["metadata"].(map[string]interface{}) + metadata, ok := data["metadata"].(map[string]any) if !ok { - metadata = make(map[string]interface{}) + metadata = make(map[string]any) } delete(data, "metadata") diff --git a/journal/events/consumer_test.go b/journal/events/consumer_test.go index eca0fa96d..72492e183 100644 --- a/journal/events/consumer_test.go +++ b/journal/events/consumer_test.go @@ -24,10 +24,10 @@ import ( var ( operation = "users.create" - payload = map[string]interface{}{ + payload = map[string]any{ "temperature": rand.Float64(), "humidity": float64(rand.Intn(1000)), - "locations": []interface{}{ + "locations": []any{ strings.Repeat("a", 100), strings.Repeat("a", 100), }, @@ -37,15 +37,15 @@ var ( ) type testEvent struct { - data map[string]interface{} + data map[string]any err error } -func (e testEvent) Encode() (map[string]interface{}, error) { +func (e testEvent) Encode() (map[string]any, error) { return e.data, e.err } -func NewTestEvent(data map[string]interface{}, err error) testEvent { +func NewTestEvent(data map[string]any, err error) testEvent { return testEvent{data: data, err: err} } @@ -55,18 +55,18 @@ func TestHandle(t *testing.T) { cases := []struct { desc string - event map[string]interface{} + event map[string]any encodeErr error repoErr error err error }{ { desc: "success", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": float64(time.Now().UnixNano()), "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), "metadata": payload, }, @@ -74,11 +74,11 @@ func TestHandle(t *testing.T) { }, { desc: "with encode error", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": float64(time.Now().UnixNano()), "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), "metadata": payload, }, @@ -87,10 +87,10 @@ func TestHandle(t *testing.T) { }, { desc: "with missing operation", - event: map[string]interface{}{ + event: map[string]any{ "occurred_at": float64(time.Now().UnixNano()), "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), "metadata": payload, }, @@ -98,11 +98,11 @@ func TestHandle(t *testing.T) { }, { desc: "with empty operation", - event: map[string]interface{}{ + event: map[string]any{ "operation": "", "occurred_at": float64(time.Now().UnixNano()), "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), "metadata": payload, }, @@ -110,11 +110,11 @@ func TestHandle(t *testing.T) { }, { desc: "with invalid operation", - event: map[string]interface{}{ + event: map[string]any{ "operation": 1, "occurred_at": float64(time.Now().UnixNano()), "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), "metadata": payload, }, @@ -122,10 +122,10 @@ func TestHandle(t *testing.T) { }, { desc: "with missing occurred_at", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), "metadata": payload, }, @@ -133,11 +133,11 @@ func TestHandle(t *testing.T) { }, { desc: "with empty occurred_at", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": float64(0), "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), "metadata": payload, }, @@ -145,11 +145,11 @@ func TestHandle(t *testing.T) { }, { desc: "with invalid occurred_at", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": "invalid", "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), "metadata": payload, }, @@ -157,34 +157,34 @@ func TestHandle(t *testing.T) { }, { desc: "with missing metadata", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": float64(time.Now().UnixNano()), "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), }, err: nil, }, { desc: "with empty metadata", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": float64(time.Now().UnixNano()), "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), - "metadata": map[string]interface{}{}, + "metadata": map[string]any{}, }, err: nil, }, { desc: "with invalid metadata", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": float64(time.Now().UnixNano()), "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), "metadata": 1, }, @@ -192,7 +192,7 @@ func TestHandle(t *testing.T) { }, { desc: "with missing attributes", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": float64(time.Now().UnixNano()), "metadata": payload, @@ -201,11 +201,11 @@ func TestHandle(t *testing.T) { }, { desc: "with empty attributes", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": float64(time.Now().UnixNano()), "id": "", - "tags": []interface{}{}, + "tags": []any{}, "number": float64(0), "metadata": payload, }, @@ -213,20 +213,20 @@ func TestHandle(t *testing.T) { }, { desc: "with invalid attributes", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": float64(time.Now().UnixNano()), - "nested": map[string]interface{}{ + "nested": map[string]any{ "key": float64(rand.Intn(1000)), - "nested": map[string]interface{}{ + "nested": map[string]any{ "key": float64(rand.Intn(1000)), - "nested": map[string]interface{}{ + "nested": map[string]any{ "key": float64(rand.Intn(1000)), - "nested": map[string]interface{}{ + "nested": map[string]any{ "key": float64(rand.Intn(1000)), - "nested": map[string]interface{}{ + "nested": map[string]any{ "key": float64(rand.Intn(1000)), - "nested": map[string]interface{}{ + "nested": map[string]any{ "key": float64(rand.Intn(1000)), }, }, @@ -240,11 +240,11 @@ func TestHandle(t *testing.T) { }, { desc: "success", - event: map[string]interface{}{ + event: map[string]any{ "operation": operation, "occurred_at": float64(time.Now().UnixNano()), "id": testsutil.GenerateUUID(t), - "tags": []interface{}{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, + "tags": []any{testsutil.GenerateUUID(t), testsutil.GenerateUUID(t)}, "number": float64(rand.Intn(1000)), "metadata": payload, }, @@ -258,7 +258,7 @@ func TestHandle(t *testing.T) { data, err := json.Marshal(tc.event) assert.NoError(t, err) - event := map[string]interface{}{} + event := map[string]any{} err = json.Unmarshal(data, &event) assert.NoError(t, err) diff --git a/journal/journal.go b/journal/journal.go index 7118db4d7..ea77134d6 100644 --- a/journal/journal.go +++ b/journal/journal.go @@ -79,12 +79,12 @@ func (e EntityType) Query() string { // Journal represents an event journal that occurred in the system. type Journal struct { - ID string `json:"id,omitempty" db:"id"` - Domain string `json:"domain,omitempty" db:"domain"` - Operation string `json:"operation,omitempty" db:"operation,omitempty"` - OccurredAt time.Time `json:"occurred_at,omitempty" db:"occurred_at,omitempty"` - Attributes map[string]interface{} `json:"attributes,omitempty" db:"attributes,omitempty"` // This is extra information about the journal for example client_id, user_id, group_id etc. - Metadata map[string]interface{} `json:"metadata,omitempty" db:"metadata,omitempty"` // This is decoded metadata from the journal. + ID string `json:"id,omitempty" db:"id"` + Domain string `json:"domain,omitempty" db:"domain"` + Operation string `json:"operation,omitempty" db:"operation,omitempty"` + OccurredAt time.Time `json:"occurred_at,omitempty" db:"occurred_at,omitempty"` + Attributes map[string]any `json:"attributes,omitempty" db:"attributes,omitempty"` // This is extra information about the journal for example client_id, user_id, group_id etc. + Metadata map[string]any `json:"metadata,omitempty" db:"metadata,omitempty"` // This is decoded metadata from the journal. } // JournalsPage represents a page of journals. diff --git a/journal/journal_test.go b/journal/journal_test.go index 21fefa7db..8215c3eb5 100644 --- a/journal/journal_test.go +++ b/journal/journal_test.go @@ -38,8 +38,8 @@ func TestJournalsPage_MarshalJSON(t *testing.T) { { Operation: "123", OccurredAt: occurredAt, - Attributes: map[string]interface{}{"123": "123"}, - Metadata: map[string]interface{}{"123": "123"}, + Attributes: map[string]any{"123": "123"}, + Metadata: map[string]any{"123": "123"}, }, }, }, diff --git a/journal/postgres/journal.go b/journal/postgres/journal.go index 99f6faee7..2ef04977c 100644 --- a/journal/postgres/journal.go +++ b/journal/postgres/journal.go @@ -168,14 +168,14 @@ func toDBJournal(j journal.Journal) (dbJournal, error) { } func toJournal(dbj dbJournal) (journal.Journal, error) { - var attributes map[string]interface{} + var attributes map[string]any if dbj.Attributes != nil { if err := json.Unmarshal(dbj.Attributes, &attributes); err != nil { return journal.Journal{}, errors.Wrap(repoerr.ErrMalformedEntity, err) } } - var metadata map[string]interface{} + var metadata map[string]any if dbj.Metadata != nil { if err := json.Unmarshal(dbj.Metadata, &metadata); err != nil { return journal.Journal{}, errors.Wrap(repoerr.ErrMalformedEntity, err) diff --git a/journal/postgres/journal_test.go b/journal/postgres/journal_test.go index 811437b8e..2d1fb99af 100644 --- a/journal/postgres/journal_test.go +++ b/journal/postgres/journal_test.go @@ -23,18 +23,18 @@ import ( var ( operation = "user.create" - payload = map[string]interface{}{ + payload = map[string]any{ "temperature": rand.Float64(), "humidity": float64(rand.Intn(1000)), - "locations": []interface{}{ + "locations": []any{ strings.Repeat("a", 100), strings.Repeat("a", 100), }, "status": "active", - "nested": map[string]interface{}{ - "nested": map[string]interface{}{ - "nested": map[string]interface{}{ - "nested": map[string]interface{}{ + "nested": map[string]any{ + "nested": map[string]any{ + "nested": map[string]any{ + "nested": map[string]any{ "key": "value", }, }, @@ -47,41 +47,41 @@ var ( clientOperation = "client.create" channelOperation = "channel.create" groupOperation = "group.create" - clientAttributesV1 = map[string]interface{}{ + clientAttributesV1 = map[string]any{ "id": entityID, "status": "enabled", "created_at": time.Now().Add(-time.Hour), "name": "client", - "tags": []interface{}{"tag1", "tag2"}, + "tags": []any{"tag1", "tag2"}, "domain": domain, "metadata": payload, "identity": testsutil.GenerateUUID(&testing.T{}), } - clientAttributesV2 = map[string]interface{}{ + clientAttributesV2 = map[string]any{ "entity_id": entityID, "metadata": payload, } - userAttributesV1 = map[string]interface{}{ + userAttributesV1 = map[string]any{ "id": entityID, "status": "enabled", "created_at": time.Now().Add(-time.Hour), "name": "user", - "tags": []interface{}{"tag1", "tag2"}, + "tags": []any{"tag1", "tag2"}, "domain": domain, "metadata": payload, "identity": testsutil.GenerateUUID(&testing.T{}), } - userAttributesV2 = map[string]interface{}{ + userAttributesV2 = map[string]any{ "user_id": entityID, "metadata": payload, } - channelAtttributes = map[string]interface{}{ + channelAtttributes = map[string]any{ "id": entityID, "status": "enabled", "created_at": time.Now().Add(-time.Hour), "name": "channel", } - groupAttributes = map[string]interface{}{ + groupAttributes = map[string]any{ "id": entityID, "status": "enabled", "created_at": time.Now().Add(-time.Hour), @@ -133,12 +133,12 @@ func TestJournalSave(t *testing.T) { ID: testsutil.GenerateUUID(t), Operation: operation, OccurredAt: time.Now(), - Attributes: map[string]interface{}{ - "attributes": map[string]interface{}{ - "attributes": map[string]interface{}{ - "attributes": map[string]interface{}{ - "attributes": map[string]interface{}{ - "attributes": map[string]interface{}{ + Attributes: map[string]any{ + "attributes": map[string]any{ + "attributes": map[string]any{ + "attributes": map[string]any{ + "attributes": map[string]any{ + "attributes": map[string]any{ "data": payload, }, "data": payload, @@ -151,12 +151,12 @@ func TestJournalSave(t *testing.T) { }, "data": payload, }, - Metadata: map[string]interface{}{ - "metadata": map[string]interface{}{ - "metadata": map[string]interface{}{ - "metadata": map[string]interface{}{ - "metadata": map[string]interface{}{ - "metadata": map[string]interface{}{ + Metadata: map[string]any{ + "metadata": map[string]any{ + "metadata": map[string]any{ + "metadata": map[string]any{ + "metadata": map[string]any{ + "metadata": map[string]any{ "data": payload, }, "data": payload, @@ -230,7 +230,7 @@ func TestJournalSave(t *testing.T) { ID: testsutil.GenerateUUID(t), Operation: operation, OccurredAt: time.Now(), - Attributes: map[string]interface{}{"invalid": make(chan struct{})}, + Attributes: map[string]any{"invalid": make(chan struct{})}, Metadata: payload, }, err: repoerr.ErrCreateEntity, @@ -241,7 +241,7 @@ func TestJournalSave(t *testing.T) { ID: testsutil.GenerateUUID(t), Operation: operation + ".with.empty.attributes", OccurredAt: time.Now(), - Attributes: map[string]interface{}{}, + Attributes: map[string]any{}, Metadata: payload, }, err: nil, @@ -262,7 +262,7 @@ func TestJournalSave(t *testing.T) { ID: testsutil.GenerateUUID(t), Operation: operation, OccurredAt: time.Now(), - Metadata: map[string]interface{}{"invalid": make(chan struct{})}, + Metadata: map[string]any{"invalid": make(chan struct{})}, Attributes: payload, }, err: repoerr.ErrCreateEntity, @@ -273,7 +273,7 @@ func TestJournalSave(t *testing.T) { ID: testsutil.GenerateUUID(t), Operation: operation + ".with.empty.metadata", OccurredAt: time.Now(), - Metadata: map[string]interface{}{}, + Metadata: map[string]any{}, Attributes: payload, }, err: nil, @@ -740,10 +740,10 @@ func TestJournalRetrieveAll(t *testing.T) { assert.Equal(t, tc.response.Offset, page.Offset) assert.Equal(t, tc.response.Limit, page.Limit) for i := range tc.response.Journals { - tc.response.Journals[i].Attributes = map[string]interface{}{} - page.Journals[i].Attributes = map[string]interface{}{} - tc.response.Journals[i].Metadata = map[string]interface{}{} - page.Journals[i].Metadata = map[string]interface{}{} + tc.response.Journals[i].Attributes = map[string]any{} + page.Journals[i].Attributes = map[string]any{} + tc.response.Journals[i].Metadata = map[string]any{} + page.Journals[i].Metadata = map[string]any{} tc.response.Journals[i].OccurredAt = validTimeStamp page.Journals[i].OccurredAt = validTimeStamp } diff --git a/journal/service_test.go b/journal/service_test.go index bec590add..4bfd34b2b 100644 --- a/journal/service_test.go +++ b/journal/service_test.go @@ -25,11 +25,11 @@ var ( validJournal = journal.Journal{ Operation: "user.create", OccurredAt: time.Now().Add(-time.Hour), - Attributes: map[string]interface{}{ + Attributes: map[string]any{ "temperature": rand.Float64(), "humidity": rand.Float64(), }, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "sensor_id": rand.Intn(1000), }, } diff --git a/mqtt/events/events.go b/mqtt/events/events.go index 3eaa36bce..943ee00eb 100644 --- a/mqtt/events/events.go +++ b/mqtt/events/events.go @@ -24,8 +24,8 @@ type connectEvent struct { instance string } -func (ce connectEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (ce connectEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": ce.operation, "client_id": ce.clientID, "subscriber_id": ce.subscriberID, @@ -42,8 +42,8 @@ type subscribeEvent struct { subtopic string } -func (se subscribeEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (se subscribeEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": se.operation, "client_id": se.clientID, "subscriber_id": se.subscriberID, diff --git a/pkg/callout/callout.go b/pkg/callout/callout.go index 25fbd6273..1675ef2cf 100644 --- a/pkg/callout/callout.go +++ b/pkg/callout/callout.go @@ -48,7 +48,7 @@ type CallOutReq struct { // Callout send request to an external service. type Callout interface { - Callout(ctx context.Context, perm string, pl map[string]interface{}) error + Callout(ctx context.Context, perm string, pl map[string]any) error } // New creates a new instance of Callout. @@ -161,7 +161,7 @@ func (c *callout) makeRequest(ctx context.Context, urlStr string, params map[str return nil } -func (c *callout) Callout(ctx context.Context, op string, pl map[string]interface{}) error { +func (c *callout) Callout(ctx context.Context, op string, pl map[string]any) error { if len(c.urls) == 0 { return nil } diff --git a/pkg/callout/callout_test.go b/pkg/callout/callout_test.go index 43f8a27a4..f6c35f598 100644 --- a/pkg/callout/callout_test.go +++ b/pkg/callout/callout_test.go @@ -32,7 +32,7 @@ const ( filePermission = 0o644 ) -var pl = map[string]interface{}{ +var pl = map[string]any{ "entity_type": entityType, "sender": userID, "domain": domainID, @@ -339,13 +339,13 @@ func TestCallout_Operations(t *testing.T) { cases := []struct { desc string operations []string - payload map[string]interface{} + payload map[string]any serverCalled bool }{ { desc: "matching operation is called", operations: []string{operation}, - payload: map[string]interface{}{ + payload: map[string]any{ "entity_type": entityType, "sender": userID, "domain": domainID, @@ -357,7 +357,7 @@ func TestCallout_Operations(t *testing.T) { { desc: "non-matching operation is not called", operations: []string{"other_operation"}, - payload: map[string]interface{}{ + payload: map[string]any{ "entity_type": entityType, "sender": userID, "domain": domainID, @@ -369,7 +369,7 @@ func TestCallout_Operations(t *testing.T) { { desc: "empty operations list calls always", operations: []string{}, - payload: map[string]interface{}{ + payload: map[string]any{ "entity_type": entityType, "sender": userID, "domain": domainID, diff --git a/pkg/callout/mocks/callout.go b/pkg/callout/mocks/callout.go index 9ea96c88b..abe737aec 100644 --- a/pkg/callout/mocks/callout.go +++ b/pkg/callout/mocks/callout.go @@ -41,7 +41,7 @@ func (_m *Callout) EXPECT() *Callout_Expecter { } // Callout provides a mock function for the type Callout -func (_mock *Callout) Callout(ctx context.Context, perm string, pl map[string]interface{}) error { +func (_mock *Callout) Callout(ctx context.Context, perm string, pl map[string]any) error { ret := _mock.Called(ctx, perm, pl) if len(ret) == 0 { @@ -49,7 +49,7 @@ func (_mock *Callout) Callout(ctx context.Context, perm string, pl map[string]in } var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string, map[string]interface{}) error); ok { + if returnFunc, ok := ret.Get(0).(func(context.Context, string, map[string]any) error); ok { r0 = returnFunc(ctx, perm, pl) } else { r0 = ret.Error(0) @@ -65,12 +65,12 @@ type Callout_Callout_Call struct { // Callout is a helper method to define mock.On call // - ctx context.Context // - perm string -// - pl map[string]interface{} +// - pl map[string]any func (_e *Callout_Expecter) Callout(ctx interface{}, perm interface{}, pl interface{}) *Callout_Callout_Call { return &Callout_Callout_Call{Call: _e.mock.On("Callout", ctx, perm, pl)} } -func (_c *Callout_Callout_Call) Run(run func(ctx context.Context, perm string, pl map[string]interface{})) *Callout_Callout_Call { +func (_c *Callout_Callout_Call) Run(run func(ctx context.Context, perm string, pl map[string]any)) *Callout_Callout_Call { _c.Call.Run(func(args mock.Arguments) { var arg0 context.Context if args[0] != nil { @@ -80,9 +80,9 @@ func (_c *Callout_Callout_Call) Run(run func(ctx context.Context, perm string, p if args[1] != nil { arg1 = args[1].(string) } - var arg2 map[string]interface{} + var arg2 map[string]any if args[2] != nil { - arg2 = args[2].(map[string]interface{}) + arg2 = args[2].(map[string]any) } run( arg0, @@ -98,7 +98,7 @@ func (_c *Callout_Callout_Call) Return(err error) *Callout_Callout_Call { return _c } -func (_c *Callout_Callout_Call) RunAndReturn(run func(ctx context.Context, perm string, pl map[string]interface{}) error) *Callout_Callout_Call { +func (_c *Callout_Callout_Call) RunAndReturn(run func(ctx context.Context, perm string, pl map[string]any) error) *Callout_Callout_Call { _c.Call.Return(run) return _c } diff --git a/pkg/domains/events/consumer/decode.go b/pkg/domains/events/consumer/decode.go index 301fbb872..369d6fe8d 100644 --- a/pkg/domains/events/consumer/decode.go +++ b/pkg/domains/events/consumer/decode.go @@ -36,7 +36,7 @@ var ( errUpdatedAt = errors.New("failed to parse 'updated_at' time") ) -func ToDomains(data map[string]interface{}) (domains.Domain, error) { +func ToDomains(data map[string]any) (domains.Domain, error) { var d domains.Domain id, ok := data["id"].(string) if !ok { @@ -83,7 +83,7 @@ func ToDomains(data map[string]interface{}) (domains.Domain, error) { d.CreatedAt = ct // Following fields of groups are allowed to be empty. - itags, ok := data["tags"].([]interface{}) + itags, ok := data["tags"].([]any) if ok { tags, err := rconsumer.ToStrings(itags) if err != nil { @@ -92,7 +92,7 @@ func ToDomains(data map[string]interface{}) (domains.Domain, error) { d.Tags = tags } - meta, ok := data["metadata"].(map[string]interface{}) + meta, ok := data["metadata"].(map[string]any) if ok { d.Metadata = meta } @@ -114,12 +114,12 @@ func ToDomains(data map[string]interface{}) (domains.Domain, error) { return d, nil } -func decodeCreateDomainEvent(data map[string]interface{}) (domains.Domain, []roles.RoleProvision, error) { +func decodeCreateDomainEvent(data map[string]any) (domains.Domain, []roles.RoleProvision, error) { d, err := ToDomains(data) if err != nil { return domains.Domain{}, []roles.RoleProvision{}, errors.Wrap(errDecodeCreateDomainEvent, err) } - irps, ok := data["roles_provisioned"].([]interface{}) + irps, ok := data["roles_provisioned"].([]any) if !ok { return domains.Domain{}, []roles.RoleProvision{}, errors.Wrap(errDecodeCreateDomainEvent, errors.New("missing or invalid 'roles_provisioned'")) } @@ -131,7 +131,7 @@ func decodeCreateDomainEvent(data map[string]interface{}) (domains.Domain, []rol return d, rps, nil } -func decodeUpdateDomainEvent(data map[string]interface{}) (domains.Domain, error) { +func decodeUpdateDomainEvent(data map[string]any) (domains.Domain, error) { var d domains.Domain id, ok := data["id"].(string) @@ -150,7 +150,7 @@ func decodeUpdateDomainEvent(data map[string]interface{}) (domains.Domain, error d.Route = route } - itags, ok := data["tags"].([]interface{}) + itags, ok := data["tags"].([]any) if ok { tags, err := rconsumer.ToStrings(itags) if err != nil { @@ -159,7 +159,7 @@ func decodeUpdateDomainEvent(data map[string]interface{}) (domains.Domain, error d.Tags = tags } - meta, ok := data["metadata"].(map[string]interface{}) + meta, ok := data["metadata"].(map[string]any) if ok { d.Metadata = meta } @@ -181,7 +181,7 @@ func decodeUpdateDomainEvent(data map[string]interface{}) (domains.Domain, error return d, nil } -func decodeEnableDomainEvent(data map[string]interface{}) (domains.Domain, error) { +func decodeEnableDomainEvent(data map[string]any) (domains.Domain, error) { var d domains.Domain id, ok := data["id"].(string) if !ok { @@ -206,7 +206,7 @@ func decodeEnableDomainEvent(data map[string]interface{}) (domains.Domain, error return d, nil } -func decodeDisableDomainEvent(data map[string]interface{}) (domains.Domain, error) { +func decodeDisableDomainEvent(data map[string]any) (domains.Domain, error) { var d domains.Domain id, ok := data["id"].(string) if !ok { @@ -231,7 +231,7 @@ func decodeDisableDomainEvent(data map[string]interface{}) (domains.Domain, erro return d, nil } -func decodeFreezeDomainEvent(data map[string]interface{}) (domains.Domain, error) { +func decodeFreezeDomainEvent(data map[string]any) (domains.Domain, error) { var d domains.Domain id, ok := data["id"].(string) if !ok { @@ -256,11 +256,11 @@ func decodeFreezeDomainEvent(data map[string]interface{}) (domains.Domain, error return d, nil } -func decodeUserDeleteDomainEvent(_ map[string]interface{}) (domains.Domain, error) { +func decodeUserDeleteDomainEvent(_ map[string]any) (domains.Domain, error) { return domains.Domain{}, fmt.Errorf("not implemented decode domain user delete event ") } -func decodeDeleteDomainEvent(data map[string]interface{}) (domains.Domain, error) { +func decodeDeleteDomainEvent(data map[string]any) (domains.Domain, error) { var d domains.Domain id, ok := data["id"].(string) if !ok { diff --git a/pkg/domains/events/consumer/stream.go b/pkg/domains/events/consumer/stream.go index d965ace61..bb1fa87b8 100644 --- a/pkg/domains/events/consumer/stream.go +++ b/pkg/domains/events/consumer/stream.go @@ -100,7 +100,7 @@ func (es *eventHandler) Handle(ctx context.Context, event events.Event) error { return es.rolesEventHandler.Handle(ctx, op, msg) } -func (es *eventHandler) createDomainHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) createDomainHandler(ctx context.Context, data map[string]any) error { d, rps, err := decodeCreateDomainEvent(data) if err != nil { return errors.Wrap(errCreateDomainEvent, err) @@ -116,7 +116,7 @@ func (es *eventHandler) createDomainHandler(ctx context.Context, data map[string return nil } -func (es *eventHandler) updateDomainHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) updateDomainHandler(ctx context.Context, data map[string]any) error { d, err := decodeUpdateDomainEvent(data) if err != nil { return errors.Wrap(errUpdateDomainEvent, err) @@ -139,7 +139,7 @@ func (es *eventHandler) updateDomainHandler(ctx context.Context, data map[string return nil } -func (es *eventHandler) enableDomainHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) enableDomainHandler(ctx context.Context, data map[string]any) error { d, err := decodeEnableDomainEvent(data) if err != nil { return errors.Wrap(errEnableDomainGroupEvent, err) @@ -153,7 +153,7 @@ func (es *eventHandler) enableDomainHandler(ctx context.Context, data map[string return nil } -func (es *eventHandler) disableDomainHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) disableDomainHandler(ctx context.Context, data map[string]any) error { d, err := decodeDisableDomainEvent(data) if err != nil { return errors.Wrap(errDisableDomainGroupEvent, err) @@ -167,7 +167,7 @@ func (es *eventHandler) disableDomainHandler(ctx context.Context, data map[strin return nil } -func (es *eventHandler) freezeDomainHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) freezeDomainHandler(ctx context.Context, data map[string]any) error { d, err := decodeFreezeDomainEvent(data) if err != nil { return errors.Wrap(errFreezeDomainGroupEvent, err) @@ -181,7 +181,7 @@ func (es *eventHandler) freezeDomainHandler(ctx context.Context, data map[string return nil } -func (es *eventHandler) userDeleteDomainHandler(_ context.Context, data map[string]interface{}) error { +func (es *eventHandler) userDeleteDomainHandler(_ context.Context, data map[string]any) error { _, err := decodeUserDeleteDomainEvent(data) if err != nil { return errors.Wrap(errUserDeleteDomainEvent, err) @@ -190,7 +190,7 @@ func (es *eventHandler) userDeleteDomainHandler(_ context.Context, data map[stri return fmt.Errorf("not implemented user delete domain handler") } -func (es *eventHandler) deleteDomainHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) deleteDomainHandler(ctx context.Context, data map[string]any) error { d, err := decodeDeleteDomainEvent(data) if err != nil { return errors.Wrap(errDeleteDomainEvent, err) diff --git a/pkg/events/events.go b/pkg/events/events.go index 575642550..e37fe45ec 100644 --- a/pkg/events/events.go +++ b/pkg/events/events.go @@ -20,7 +20,7 @@ const ( // Event represents an event. type Event interface { // Encode encodes event to map. - Encode() (map[string]interface{}, error) + Encode() (map[string]any, error) } // Publisher specifies events publishing API. @@ -58,7 +58,7 @@ type Subscriber interface { // Read reads value from event map. // If value is not of type T, returns default value. -func Read[T any](event map[string]interface{}, key string, def T) T { +func Read[T any](event map[string]any, key string, def T) T { val, ok := event[key].(T) if !ok { return def @@ -69,10 +69,10 @@ func Read[T any](event map[string]interface{}, key string, def T) T { // ReadStringSlice reads string slice from event map. // If value is not a string slice, returns empty slice. -func ReadStringSlice(event map[string]interface{}, key string) []string { +func ReadStringSlice(event map[string]any, key string) []string { var res []string - vals, ok := event[key].([]interface{}) + vals, ok := event[key].([]any) if !ok { return res } diff --git a/pkg/events/nats/publisher_test.go b/pkg/events/nats/publisher_test.go index b6430fcb9..bf01ec4f0 100644 --- a/pkg/events/nats/publisher_test.go +++ b/pkg/events/nats/publisher_test.go @@ -19,18 +19,18 @@ import ( ) var ( - eventsChan = make(chan map[string]interface{}) + eventsChan = make(chan map[string]any) logger = smqlog.NewMock() errFailed = errors.New("failed") numEvents = 100 ) type testEvent struct { - Data map[string]interface{} + Data map[string]any } -func (te testEvent) Encode() (map[string]interface{}, error) { - data := make(map[string]interface{}) +func (te testEvent) Encode() (map[string]any, error) { + data := make(map[string]any) for k, v := range te.Data { switch v.(type) { case string: @@ -74,13 +74,13 @@ func TestPublish(t *testing.T) { cases := []struct { desc string - event map[string]interface{} + event map[string]any err error }{ { desc: "publish event successfully", err: nil, - event: map[string]interface{}{ + event: map[string]any{ "temperature": fmt.Sprintf("%f", rand.Float64()), "humidity": fmt.Sprintf("%f", rand.Float64()), "sensor_id": "abc123", @@ -99,7 +99,7 @@ func TestPublish(t *testing.T) { { desc: "publish event with invalid event location", err: fmt.Errorf("json: unsupported type: chan int"), - event: map[string]interface{}{ + event: map[string]any{ "temperature": fmt.Sprintf("%f", rand.Float64()), "humidity": fmt.Sprintf("%f", rand.Float64()), "sensor_id": "abc123", @@ -113,7 +113,7 @@ func TestPublish(t *testing.T) { { desc: "publish event with nested sting value", err: nil, - event: map[string]interface{}{ + event: map[string]any{ "temperature": fmt.Sprintf("%f", rand.Float64()), "humidity": fmt.Sprintf("%f", rand.Float64()), "sensor_id": "abc123", @@ -275,7 +275,7 @@ func TestUnavailablePublish(t *testing.T) { assert.Nil(t, err, fmt.Sprintf("got unexpected error on closing publisher: %s", err)) // read all the events from the channel and assert that they are 10. - var receivedEvents []map[string]interface{} + var receivedEvents []map[string]any for i := 0; i < numEvents; i++ { event := <-eventsChan receivedEvents = append(receivedEvents, event) @@ -285,7 +285,7 @@ func TestUnavailablePublish(t *testing.T) { func generateRandomEvent() testEvent { return testEvent{ - Data: map[string]interface{}{ + Data: map[string]any{ "temperature": fmt.Sprintf("%f", rand.Float64()), "humidity": fmt.Sprintf("%f", rand.Float64()), "sensor_id": fmt.Sprintf("%d", rand.Intn(1000)), diff --git a/pkg/events/nats/subscriber.go b/pkg/events/nats/subscriber.go index 91b423162..4dde230d5 100644 --- a/pkg/events/nats/subscriber.go +++ b/pkg/events/nats/subscriber.go @@ -83,10 +83,10 @@ func (es *subEventStore) Close() error { } type event struct { - Data map[string]interface{} + Data map[string]any } -func (re event) Encode() (map[string]interface{}, error) { +func (re event) Encode() (map[string]any, error) { return re.Data, nil } @@ -97,7 +97,7 @@ type eventHandler struct { func (eh *eventHandler) Handle(msg *messaging.Message) error { event := event{ - Data: make(map[string]interface{}), + Data: make(map[string]any), } if err := json.Unmarshal(msg.GetPayload(), &event.Data); err != nil { diff --git a/pkg/events/rabbitmq/publisher_test.go b/pkg/events/rabbitmq/publisher_test.go index 3263fe536..395fbbc55 100644 --- a/pkg/events/rabbitmq/publisher_test.go +++ b/pkg/events/rabbitmq/publisher_test.go @@ -19,18 +19,18 @@ import ( ) var ( - eventsChan = make(chan map[string]interface{}) + eventsChan = make(chan map[string]any) logger = smqlog.NewMock() errFailed = errors.New("failed") numEvents = 100 ) type testEvent struct { - Data map[string]interface{} + Data map[string]any } -func (te testEvent) Encode() (map[string]interface{}, error) { - data := make(map[string]interface{}) +func (te testEvent) Encode() (map[string]any, error) { + data := make(map[string]any) for k, v := range te.Data { switch v.(type) { case string: @@ -74,13 +74,13 @@ func TestPublish(t *testing.T) { cases := []struct { desc string - event map[string]interface{} + event map[string]any err error }{ { desc: "publish event successfully", err: nil, - event: map[string]interface{}{ + event: map[string]any{ "temperature": fmt.Sprintf("%f", rand.Float64()), "humidity": fmt.Sprintf("%f", rand.Float64()), "sensor_id": "abc123", @@ -99,7 +99,7 @@ func TestPublish(t *testing.T) { { desc: "publish event with invalid event location", err: fmt.Errorf("json: unsupported type: chan int"), - event: map[string]interface{}{ + event: map[string]any{ "temperature": fmt.Sprintf("%f", rand.Float64()), "humidity": fmt.Sprintf("%f", rand.Float64()), "sensor_id": "abc123", @@ -113,7 +113,7 @@ func TestPublish(t *testing.T) { { desc: "publish event with nested sting value", err: nil, - event: map[string]interface{}{ + event: map[string]any{ "temperature": fmt.Sprintf("%f", rand.Float64()), "humidity": fmt.Sprintf("%f", rand.Float64()), "sensor_id": "abc123", @@ -276,7 +276,7 @@ func TestUnavailablePublish(t *testing.T) { assert.Nil(t, err, fmt.Sprintf("got unexpected error on closing publisher: %s", err)) // read all the events from the channel and assert that they are 10. - var receivedEvents []map[string]interface{} + var receivedEvents []map[string]any for i := 0; i < numEvents; i++ { event := <-eventsChan receivedEvents = append(receivedEvents, event) @@ -286,7 +286,7 @@ func TestUnavailablePublish(t *testing.T) { func generateRandomEvent() testEvent { return testEvent{ - Data: map[string]interface{}{ + Data: map[string]any{ "temperature": fmt.Sprintf("%f", rand.Float64()), "humidity": fmt.Sprintf("%f", rand.Float64()), "sensor_id": fmt.Sprintf("%d", rand.Intn(1000)), diff --git a/pkg/events/rabbitmq/subscriber.go b/pkg/events/rabbitmq/subscriber.go index fbb5c2279..571050d02 100644 --- a/pkg/events/rabbitmq/subscriber.go +++ b/pkg/events/rabbitmq/subscriber.go @@ -69,10 +69,10 @@ func (es *subEventStore) Close() error { } type event struct { - Data map[string]interface{} + Data map[string]any } -func (re event) Encode() (map[string]interface{}, error) { +func (re event) Encode() (map[string]any, error) { return re.Data, nil } @@ -83,7 +83,7 @@ type eventHandler struct { func (eh *eventHandler) Handle(msg *messaging.Message) error { event := event{ - Data: make(map[string]interface{}), + Data: make(map[string]any), } if err := json.Unmarshal(msg.GetPayload(), &event.Data); err != nil { diff --git a/pkg/events/redis/publisher.go b/pkg/events/redis/publisher.go index 9b7062bc6..889e6ee04 100644 --- a/pkg/events/redis/publisher.go +++ b/pkg/events/redis/publisher.go @@ -53,7 +53,7 @@ func (es *pubEventStore) Publish(ctx context.Context, stream string, event event Stream: eventsPrefix + stream, MaxLen: events.MaxEventStreamLen, Approx: true, - Values: map[string]interface{}{"data": string(data)}, + Values: map[string]any{"data": string(data)}, } switch err := es.checkConnection(ctx); err { diff --git a/pkg/events/redis/publisher_test.go b/pkg/events/redis/publisher_test.go index 00b1c2024..ae6488845 100644 --- a/pkg/events/redis/publisher_test.go +++ b/pkg/events/redis/publisher_test.go @@ -20,19 +20,19 @@ import ( var ( stream = "tests.events" consumer = "test-consumer" - eventsChan = make(chan map[string]interface{}) + eventsChan = make(chan map[string]any) logger = smqlog.NewMock() errFailed = errors.New("failed") numEvents = 100 ) type testEvent struct { - Data map[string]interface{} + Data map[string]any } -func (te testEvent) Encode() (map[string]interface{}, error) { +func (te testEvent) Encode() (map[string]any, error) { if te.Data == nil { - return map[string]interface{}{}, nil + return map[string]any{}, nil } return te.Data, nil @@ -66,13 +66,13 @@ func TestPublish(t *testing.T) { cases := []struct { desc string - event map[string]interface{} + event map[string]any err error }{ { desc: "publish event successfully", err: nil, - event: map[string]interface{}{ + event: map[string]any{ "temperature": float64(rand.Float64()), "humidity": float64(rand.Float64()), "sensor_id": "abc123", @@ -91,7 +91,7 @@ func TestPublish(t *testing.T) { { desc: "publish event with invalid event location", err: fmt.Errorf("json: unsupported type: chan int"), - event: map[string]interface{}{ + event: map[string]any{ "temperature": float64(rand.Float64()), "humidity": float64(rand.Float64()), "sensor_id": "abc123", @@ -105,7 +105,7 @@ func TestPublish(t *testing.T) { { desc: "publish event with nested sting value", err: nil, - event: map[string]interface{}{ + event: map[string]any{ "temperature": float64(rand.Float64()), "humidity": float64(rand.Float64()), "sensor_id": "abc123", @@ -271,7 +271,7 @@ func TestUnavailablePublish(t *testing.T) { err = publisher.Close() assert.Nil(t, err, fmt.Sprintf("got unexpected error on closing publisher: %s", err)) - var receivedEvents []map[string]interface{} + var receivedEvents []map[string]any for i := 0; i < numEvents; i++ { event := <-eventsChan receivedEvents = append(receivedEvents, event) @@ -281,7 +281,7 @@ func TestUnavailablePublish(t *testing.T) { func generateRandomEvent() testEvent { return testEvent{ - Data: map[string]interface{}{ + Data: map[string]any{ "temperature": fmt.Sprintf("%f", rand.Float64()), "humidity": fmt.Sprintf("%f", rand.Float64()), "sensor_id": fmt.Sprintf("%d", rand.Intn(1000)), diff --git a/pkg/events/redis/subscriber.go b/pkg/events/redis/subscriber.go index 8900fd521..c5af81d8a 100644 --- a/pkg/events/redis/subscriber.go +++ b/pkg/events/redis/subscriber.go @@ -90,16 +90,16 @@ func (es *subEventStore) Close() error { } type redisEvent struct { - Data map[string]interface{} + Data map[string]any } -func (re redisEvent) Encode() (map[string]interface{}, error) { +func (re redisEvent) Encode() (map[string]any, error) { return re.Data, nil } func (es *subEventStore) handle(ctx context.Context, stream string, msgs []redis.XMessage, h events.EventHandler) { for _, msg := range msgs { - var data map[string]interface{} + var data map[string]any if err := json.Unmarshal([]byte(msg.Values["data"].(string)), &data); err != nil { es.logger.Warn(fmt.Sprintf("failed to unmarshal redis event: %s", err)) diff --git a/pkg/groups/events/consumer/decode.go b/pkg/groups/events/consumer/decode.go index 86c70c674..ed9458cda 100644 --- a/pkg/groups/events/consumer/decode.go +++ b/pkg/groups/events/consumer/decode.go @@ -36,7 +36,7 @@ var ( const layout = "2006-01-02T15:04:05.999999Z" -func ToGroups(data map[string]interface{}) (groups.Group, error) { +func ToGroups(data map[string]any) (groups.Group, error) { var g groups.Group id, ok := data["id"].(string) if !ok { @@ -88,7 +88,7 @@ func ToGroups(data map[string]interface{}) (groups.Group, error) { g.Parent = parent } - meta, ok := data["metadata"].(map[string]interface{}) + meta, ok := data["metadata"].(map[string]any) if ok { g.Metadata = meta } @@ -110,12 +110,12 @@ func ToGroups(data map[string]interface{}) (groups.Group, error) { return g, nil } -func decodeCreateGroupEvent(data map[string]interface{}) (groups.Group, []roles.RoleProvision, error) { +func decodeCreateGroupEvent(data map[string]any) (groups.Group, []roles.RoleProvision, error) { g, err := ToGroups(data) if err != nil { return groups.Group{}, []roles.RoleProvision{}, errors.Wrap(errDecodeCreateGroupEvent, err) } - irps, ok := data["roles_provisioned"].([]interface{}) + irps, ok := data["roles_provisioned"].([]any) if !ok { return groups.Group{}, []roles.RoleProvision{}, errors.Wrap(errDecodeCreateGroupEvent, errors.New("missing or invalid 'roles_provisioned'")) } @@ -127,7 +127,7 @@ func decodeCreateGroupEvent(data map[string]interface{}) (groups.Group, []roles. return g, rps, nil } -func decodeUpdateGroupEvent(data map[string]interface{}) (groups.Group, error) { +func decodeUpdateGroupEvent(data map[string]any) (groups.Group, error) { g, err := ToGroups(data) if err != nil { return groups.Group{}, errors.Wrap(errDecodeUpdateGroupEvent, err) @@ -135,7 +135,7 @@ func decodeUpdateGroupEvent(data map[string]interface{}) (groups.Group, error) { return g, nil } -func ToGroupStatus(data map[string]interface{}) (groups.Group, error) { +func ToGroupStatus(data map[string]any) (groups.Group, error) { var g groups.Group id, ok := data["id"].(string) if !ok { @@ -170,7 +170,7 @@ func ToGroupStatus(data map[string]interface{}) (groups.Group, error) { return g, nil } -func decodeChangeStatusGroupEvent(data map[string]interface{}) (groups.Group, error) { +func decodeChangeStatusGroupEvent(data map[string]any) (groups.Group, error) { g, err := ToGroupStatus(data) if err != nil { return groups.Group{}, errors.Wrap(errDecodeChangeStatusGroupEvent, err) @@ -178,7 +178,7 @@ func decodeChangeStatusGroupEvent(data map[string]interface{}) (groups.Group, er return g, nil } -func decodeRemoveGroupEvent(data map[string]interface{}) (groups.Group, error) { +func decodeRemoveGroupEvent(data map[string]any) (groups.Group, error) { var g groups.Group id, ok := data["id"].(string) if !ok { @@ -189,7 +189,7 @@ func decodeRemoveGroupEvent(data map[string]interface{}) (groups.Group, error) { return g, nil } -func decodeAddParentGroupEvent(data map[string]interface{}) (id string, parent string, err error) { +func decodeAddParentGroupEvent(data map[string]any) (id string, parent string, err error) { id, ok := data["id"].(string) if !ok { return "", "", errors.Wrap(errAddParentGroupEvent, errID) @@ -203,7 +203,7 @@ func decodeAddParentGroupEvent(data map[string]interface{}) (id string, parent s return id, parent, nil } -func decodeRemoveParentGroupEvent(data map[string]interface{}) (id string, err error) { +func decodeRemoveParentGroupEvent(data map[string]any) (id string, err error) { id, ok := data["id"].(string) if !ok { return "", errors.Wrap(errDecodeRemoveParentGroupEvent, errID) @@ -212,12 +212,12 @@ func decodeRemoveParentGroupEvent(data map[string]interface{}) (id string, err e return id, nil } -func decodeAddChildrenGroupEvent(data map[string]interface{}) (id string, childrenIDs []string, err error) { +func decodeAddChildrenGroupEvent(data map[string]any) (id string, childrenIDs []string, err error) { id, ok := data["id"].(string) if !ok { return "", []string{}, errors.Wrap(errDecodeAddChildrenGroupsEvent, errID) } - chIDs, ok := data["children_ids"].([]interface{}) + chIDs, ok := data["children_ids"].([]any) if !ok { return "", []string{}, errors.Wrap(errDecodeAddChildrenGroupsEvent, errChildrenIDs) } @@ -228,12 +228,12 @@ func decodeAddChildrenGroupEvent(data map[string]interface{}) (id string, childr return id, cids, nil } -func decodeRemoveChildrenGroupEvent(data map[string]interface{}) (id string, childrenIDs []string, err error) { +func decodeRemoveChildrenGroupEvent(data map[string]any) (id string, childrenIDs []string, err error) { id, ok := data["id"].(string) if !ok { return "", []string{}, errors.Wrap(errDecodeRemoveChildrenGroupsEvent, errID) } - chIDs, ok := data["children_ids"].([]interface{}) + chIDs, ok := data["children_ids"].([]any) if !ok { return "", []string{}, errors.Wrap(errDecodeRemoveChildrenGroupsEvent, errChildrenIDs) } @@ -244,7 +244,7 @@ func decodeRemoveChildrenGroupEvent(data map[string]interface{}) (id string, chi return id, cids, nil } -func decodeRemoveAllChildrenGroupEvent(data map[string]interface{}) (id string, err error) { +func decodeRemoveAllChildrenGroupEvent(data map[string]any) (id string, err error) { id, ok := data["id"].(string) if !ok { return "", errors.Wrap(errDecodeRemoveChildrenGroupsEvent, errID) diff --git a/pkg/groups/events/consumer/streams.go b/pkg/groups/events/consumer/streams.go index 882cd061c..2e39e0ea2 100644 --- a/pkg/groups/events/consumer/streams.go +++ b/pkg/groups/events/consumer/streams.go @@ -107,7 +107,7 @@ func (es *eventHandler) Handle(ctx context.Context, event events.Event) error { return es.rolesEventHandler.Handle(ctx, op, msg) } -func (es *eventHandler) createGroupHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) createGroupHandler(ctx context.Context, data map[string]any) error { g, rps, err := decodeCreateGroupEvent(data) if err != nil { return errors.Wrap(errCreateGroupEvent, err) @@ -123,7 +123,7 @@ func (es *eventHandler) createGroupHandler(ctx context.Context, data map[string] return nil } -func (es *eventHandler) updateGroupHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) updateGroupHandler(ctx context.Context, data map[string]any) error { g, err := decodeUpdateGroupEvent(data) if err != nil { return errors.Wrap(errUpdateGroupEvent, err) @@ -136,7 +136,7 @@ func (es *eventHandler) updateGroupHandler(ctx context.Context, data map[string] return nil } -func (es *eventHandler) changeStatusGroupHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) changeStatusGroupHandler(ctx context.Context, data map[string]any) error { g, err := decodeChangeStatusGroupEvent(data) if err != nil { return errors.Wrap(errChangeStatusGroupEvent, err) @@ -149,7 +149,7 @@ func (es *eventHandler) changeStatusGroupHandler(ctx context.Context, data map[s return nil } -func (es *eventHandler) removeGroupHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) removeGroupHandler(ctx context.Context, data map[string]any) error { g, err := decodeRemoveGroupEvent(data) if err != nil { return errors.Wrap(errRemoveGroupEvent, err) @@ -161,7 +161,7 @@ func (es *eventHandler) removeGroupHandler(ctx context.Context, data map[string] return nil } -func (es *eventHandler) addParentGroupHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) addParentGroupHandler(ctx context.Context, data map[string]any) error { id, parent, err := decodeAddParentGroupEvent(data) if err != nil { return errors.Wrap(errAddParentGroupEvent, err) @@ -172,7 +172,7 @@ func (es *eventHandler) addParentGroupHandler(ctx context.Context, data map[stri return nil } -func (es *eventHandler) removeParentGroupHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) removeParentGroupHandler(ctx context.Context, data map[string]any) error { id, err := decodeRemoveParentGroupEvent(data) if err != nil { return errors.Wrap(errRemoveParentGroupEvent, err) @@ -187,7 +187,7 @@ func (es *eventHandler) removeParentGroupHandler(ctx context.Context, data map[s return nil } -func (es *eventHandler) addChildrenGroupsHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) addChildrenGroupsHandler(ctx context.Context, data map[string]any) error { id, cids, err := decodeAddChildrenGroupEvent(data) if err != nil { return errors.Wrap(errAddChildrenGroupEvent, err) @@ -199,7 +199,7 @@ func (es *eventHandler) addChildrenGroupsHandler(ctx context.Context, data map[s return nil } -func (es *eventHandler) removeChildrenGroupsHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) removeChildrenGroupsHandler(ctx context.Context, data map[string]any) error { id, cids, err := decodeRemoveChildrenGroupEvent(data) if err != nil { return errors.Wrap(errRemoveChildrenGroupEvent, err) @@ -211,7 +211,7 @@ func (es *eventHandler) removeChildrenGroupsHandler(ctx context.Context, data ma return nil } -func (es *eventHandler) removeAllChildrenGroupsHandler(ctx context.Context, data map[string]interface{}) error { +func (es *eventHandler) removeAllChildrenGroupsHandler(ctx context.Context, data map[string]any) error { id, err := decodeRemoveAllChildrenGroupEvent(data) if err != nil { return errors.Wrap(errRemoveAllChildrenGroupEvent, err) diff --git a/pkg/messaging/events/events.go b/pkg/messaging/events/events.go index d44e8186d..54b5e423e 100644 --- a/pkg/messaging/events/events.go +++ b/pkg/messaging/events/events.go @@ -24,8 +24,8 @@ type publishEvent struct { subtopic string } -func (pe publishEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (pe publishEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": clientPublish, "domain_id": pe.domainID, "channel_id": pe.channelID, @@ -41,8 +41,8 @@ type subscribeEvent struct { topic string } -func (se subscribeEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (se subscribeEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": se.operation, "subscriber_id": se.subscriberID, "client_id": se.clientID, diff --git a/pkg/messaging/nats/options.go b/pkg/messaging/nats/options.go index ccfbf8e78..7d8ac71e2 100644 --- a/pkg/messaging/nats/options.go +++ b/pkg/messaging/nats/options.go @@ -44,7 +44,7 @@ func defaultOptions() options { // Prefix sets the prefix for the publisher or subscriber. func Prefix(prefix string) messaging.Option { - return func(val interface{}) error { + return func(val any) error { switch v := val.(type) { case *publisher: v.prefix = prefix @@ -60,7 +60,7 @@ func Prefix(prefix string) messaging.Option { // JSStreamConfig sets the JetStream for the publisher or subscriber. func JSStreamConfig(jsStreamConfig jetstream.StreamConfig) messaging.Option { - return func(val interface{}) error { + return func(val any) error { switch v := val.(type) { case *publisher: v.jsStreamConfig = jsStreamConfig diff --git a/pkg/messaging/pubsub.go b/pkg/messaging/pubsub.go index 5ee6c7945..86660fca2 100644 --- a/pkg/messaging/pubsub.go +++ b/pkg/messaging/pubsub.go @@ -115,4 +115,4 @@ type PubSub interface { // Example: // // broker.NewPublisher(ctx, url, broker.Prefix(eventsPrefix), broker.JSStream(js)) -type Option func(vals interface{}) error +type Option func(vals any) error diff --git a/pkg/messaging/rabbitmq/options.go b/pkg/messaging/rabbitmq/options.go index 4be1f67d6..e8121515a 100644 --- a/pkg/messaging/rabbitmq/options.go +++ b/pkg/messaging/rabbitmq/options.go @@ -31,7 +31,7 @@ func defaultOptions() options { // Prefix sets the prefix for the publisher. func Prefix(prefix string) messaging.Option { - return func(val interface{}) error { + return func(val any) error { switch v := val.(type) { case *publisher: v.prefix = prefix @@ -46,7 +46,7 @@ func Prefix(prefix string) messaging.Option { // Exchange sets the exchange for the publisher or subscriber. func Exchange(exchange string) messaging.Option { - return func(val interface{}) error { + return func(val any) error { switch v := val.(type) { case *publisher: v.exchange = exchange diff --git a/pkg/oauth2/normalize.go b/pkg/oauth2/normalize.go index 5bbdd19ba..b79e9d57e 100644 --- a/pkg/oauth2/normalize.go +++ b/pkg/oauth2/normalize.go @@ -21,7 +21,7 @@ type normalizedUser struct { } func NormalizeUser(data []byte, provider string) (users.User, error) { - var raw map[string]interface{} + var raw map[string]any if err := json.Unmarshal(data, &raw); err != nil { return users.User{}, err } diff --git a/pkg/oauth2/normalize_test.go b/pkg/oauth2/normalize_test.go index 3113a76ed..19423258f 100644 --- a/pkg/oauth2/normalize_test.go +++ b/pkg/oauth2/normalize_test.go @@ -74,12 +74,12 @@ func TestNormalizeUser(t *testing.T) { func TestNormalizeProfile(t *testing.T) { cases := []struct { desc string - raw map[string]interface{} - expected map[string]interface{} + raw map[string]any + expected map[string]any }{ { desc: "maps all variants to normalized keys", - raw: map[string]interface{}{ + raw: map[string]any{ "id": "id123", "givenName": "John", "familyName": "Smith", @@ -87,7 +87,7 @@ func TestNormalizeProfile(t *testing.T) { "emailAddress": "john@smith.com", "profilePicture": "pic.png", }, - expected: map[string]interface{}{ + expected: map[string]any{ "id": "id123", "first_name": "John", "last_name": "Smith", @@ -98,8 +98,8 @@ func TestNormalizeProfile(t *testing.T) { }, { desc: "missing keys returns empty map", - raw: map[string]interface{}{"foo": "bar"}, - expected: map[string]interface{}{}, + raw: map[string]any{"foo": "bar"}, + expected: map[string]any{}, }, } diff --git a/pkg/postgres/common.go b/pkg/postgres/common.go index 3f394f772..a1c7b1489 100644 --- a/pkg/postgres/common.go +++ b/pkg/postgres/common.go @@ -13,10 +13,10 @@ import ( // // For example: // -// query, param, err := CreateMetadataQuery("", map[string]interface{}{ +// query, param, err := CreateMetadataQuery("", map[string]any{ // "key": "value", // }) -func CreateMetadataQuery(entity string, um map[string]interface{}) (string, []byte, error) { +func CreateMetadataQuery(entity string, um map[string]any) (string, []byte, error) { if len(um) == 0 { return "", nil, nil } @@ -35,7 +35,7 @@ func CreateMetadataQuery(entity string, um map[string]interface{}) (string, []by // For example: // // total, err := Total(ctx, db, "SELECT COUNT(*) FROM table", nil) -func Total(ctx context.Context, db Database, query string, params interface{}) (uint64, error) { +func Total(ctx context.Context, db Database, query string, params any) (uint64, error) { rows, err := db.NamedQueryContext(ctx, query, params) if err != nil { return 0, err diff --git a/pkg/postgres/tracing.go b/pkg/postgres/tracing.go index 732d04415..4af104e54 100644 --- a/pkg/postgres/tracing.go +++ b/pkg/postgres/tracing.go @@ -26,22 +26,22 @@ type database struct { // Database provides a database interface. type Database interface { // NamedQueryContext executes a named query against the database and returns - NamedQueryContext(context.Context, string, interface{}) (*sqlx.Rows, error) + NamedQueryContext(context.Context, string, any) (*sqlx.Rows, error) // NamedExecContext executes a named query against the database and returns - NamedExecContext(context.Context, string, interface{}) (sql.Result, error) + NamedExecContext(context.Context, string, any) (sql.Result, error) // QueryRowxContext queries the database and returns an *sqlx.Row. - QueryRowxContext(context.Context, string, ...interface{}) *sqlx.Row + QueryRowxContext(context.Context, string, ...any) *sqlx.Row // QueryxContext queries the database and returns an *sqlx.Rows and an error. - QueryxContext(context.Context, string, ...interface{}) (*sqlx.Rows, error) + QueryxContext(context.Context, string, ...any) (*sqlx.Rows, error) // QueryContext queries the database and returns an *sql.Rows and an error. - QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) + QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) // ExecContext executes a query without returning any rows. - ExecContext(context.Context, string, ...interface{}) (sql.Result, error) + ExecContext(context.Context, string, ...any) (sql.Result, error) // BeginTxx begins a transaction and returns an *sqlx.Tx. BeginTxx(ctx context.Context, opts *sql.TxOptions) (*sqlx.Tx, error) @@ -61,42 +61,42 @@ func NewDatabase(db *sqlx.DB, config Config, tracer trace.Tracer) Database { return database } -func (d *database) NamedQueryContext(ctx context.Context, query string, args interface{}) (*sqlx.Rows, error) { +func (d *database) NamedQueryContext(ctx context.Context, query string, args any) (*sqlx.Rows, error) { ctx, span := d.addSpanTags(ctx, query) defer span.End() return d.db.NamedQueryContext(ctx, query, args) } -func (d *database) NamedExecContext(ctx context.Context, query string, args interface{}) (sql.Result, error) { +func (d *database) NamedExecContext(ctx context.Context, query string, args any) (sql.Result, error) { ctx, span := d.addSpanTags(ctx, query) defer span.End() return d.db.NamedExecContext(ctx, query, args) } -func (d *database) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) { +func (d *database) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) { ctx, span := d.addSpanTags(ctx, query) defer span.End() return d.db.ExecContext(ctx, query, args...) } -func (d *database) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row { +func (d *database) QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row { ctx, span := d.addSpanTags(ctx, query) defer span.End() return d.db.QueryRowxContext(ctx, query, args...) } -func (d *database) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error) { +func (d *database) QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error) { ctx, span := d.addSpanTags(ctx, query) defer span.End() return d.db.QueryxContext(ctx, query, args...) } -func (d database) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) { +func (d database) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) { ctx, span := d.addSpanTags(ctx, query) defer span.End() return d.db.QueryContext(ctx, query, args...) diff --git a/pkg/roles/repo/postgres/roles.go b/pkg/roles/repo/postgres/roles.go index 357f03493..825ba8713 100644 --- a/pkg/roles/repo/postgres/roles.go +++ b/pkg/roles/repo/postgres/roles.go @@ -251,7 +251,7 @@ func (repo *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) func (repo *Repository) RemoveRoles(ctx context.Context, roleIDs []string) error { q := fmt.Sprintf("DELETE FROM %s_roles WHERE id = ANY(:role_ids) ;", repo.tableNamePrefix) - params := map[string]interface{}{ + params := map[string]any{ "role_ids": roleIDs, } result, err := repo.db.NamedExecContext(ctx, q, params) @@ -462,7 +462,7 @@ func (repo *Repository) RoleListActions(ctx context.Context, roleID string) ([]s func (repo *Repository) RoleCheckActionsExists(ctx context.Context, roleID string, actions []string) (bool, error) { q := fmt.Sprintf(`SELECT COUNT(*) FROM %s_role_actions WHERE role_id = :role_id AND action IN ('%s')`, repo.tableNamePrefix, strings.Join(actions, ",")) - params := map[string]interface{}{ + params := map[string]any{ "role_id": roleID, } var count int @@ -502,7 +502,7 @@ func (repo *Repository) RoleRemoveActions(ctx context.Context, role roles.Role, q := fmt.Sprintf(`DELETE FROM %s_role_actions WHERE role_id = :role_id AND action = ANY(:actions)`, repo.tableNamePrefix) - params := map[string]interface{}{ + params := map[string]any{ "role_id": role.ID, "actions": actions, } @@ -640,7 +640,7 @@ func (repo *Repository) RoleListMembers(ctx context.Context, roleID string, limi func (repo *Repository) RoleCheckMembersExists(ctx context.Context, roleID string, members []string) (bool, error) { q := fmt.Sprintf(`SELECT COUNT(*) FROM %s_role_members WHERE role_id = :role_id AND member_id IN ('%s')`, repo.tableNamePrefix, strings.Join(members, ",")) - params := map[string]interface{}{ + params := map[string]any{ "role_id": roleID, } var count int @@ -679,7 +679,7 @@ func (repo *Repository) RoleRemoveMembers(ctx context.Context, role roles.Role, q := fmt.Sprintf(`DELETE FROM %s_role_members WHERE role_id = :role_id AND member_id = ANY(:member_ids)`, repo.tableNamePrefix) - params := map[string]interface{}{ + params := map[string]any{ "role_id": role.ID, "member_ids": members, } @@ -731,7 +731,7 @@ func (repo *Repository) RoleRemoveAllMembers(ctx context.Context, role roles.Rol } func (repo *Repository) RetrieveEntitiesRolesActionsMembers(ctx context.Context, entityIDs []string) ([]roles.EntityActionRole, []roles.EntityMemberRole, error) { - params := map[string]interface{}{ + params := map[string]any{ "entity_ids": entityIDs, } diff --git a/pkg/roles/rolemanager/api/decoders.go b/pkg/roles/rolemanager/api/decoders.go index 853349804..ac7c6cbed 100644 --- a/pkg/roles/rolemanager/api/decoders.go +++ b/pkg/roles/rolemanager/api/decoders.go @@ -23,7 +23,7 @@ func NewDecoder(entityIDTemplate string) Decoder { return Decoder{entityIDTemplate} } -func (d Decoder) DecodeCreateRole(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeCreateRole(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -37,7 +37,7 @@ func (d Decoder) DecodeCreateRole(_ context.Context, r *http.Request) (interface return req, nil } -func (d Decoder) DecodeListRoles(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeListRoles(_ context.Context, r *http.Request) (any, error) { o, err := apiutil.ReadNumQuery[uint64](r, api.OffsetKey, api.DefOffset) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -55,7 +55,7 @@ func (d Decoder) DecodeListRoles(_ context.Context, r *http.Request) (interface{ return req, nil } -func (d Decoder) DecodeListEntityMembers(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeListEntityMembers(_ context.Context, r *http.Request) (any, error) { o, err := apiutil.ReadNumQuery[uint64](r, api.OffsetKey, api.DefOffset) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -124,7 +124,7 @@ func (d Decoder) DecodeListEntityMembers(_ context.Context, r *http.Request) (in return req, nil } -func (d Decoder) DecodeRemoveEntityMembers(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeRemoveEntityMembers(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -140,7 +140,7 @@ func (d Decoder) DecodeRemoveEntityMembers(_ context.Context, r *http.Request) ( return req, nil } -func (d Decoder) DecodeViewRole(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeViewRole(_ context.Context, r *http.Request) (any, error) { req := viewRoleReq{ token: apiutil.ExtractBearerToken(r), entityID: chi.URLParam(r, d.entityIDTemplate), @@ -149,7 +149,7 @@ func (d Decoder) DecodeViewRole(_ context.Context, r *http.Request) (interface{} return req, nil } -func (d Decoder) DecodeUpdateRole(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeUpdateRole(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -164,7 +164,7 @@ func (d Decoder) DecodeUpdateRole(_ context.Context, r *http.Request) (interface return req, nil } -func (d Decoder) DecodeDeleteRole(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeDeleteRole(_ context.Context, r *http.Request) (any, error) { req := deleteRoleReq{ token: apiutil.ExtractBearerToken(r), entityID: chi.URLParam(r, d.entityIDTemplate), @@ -173,14 +173,14 @@ func (d Decoder) DecodeDeleteRole(_ context.Context, r *http.Request) (interface return req, nil } -func (d Decoder) DecodeListAvailableActions(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeListAvailableActions(_ context.Context, r *http.Request) (any, error) { req := listAvailableActionsReq{ token: apiutil.ExtractBearerToken(r), } return req, nil } -func (d Decoder) DecodeAddRoleActions(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeAddRoleActions(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -195,7 +195,7 @@ func (d Decoder) DecodeAddRoleActions(_ context.Context, r *http.Request) (inter return req, nil } -func (d Decoder) DecodeListRoleActions(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeListRoleActions(_ context.Context, r *http.Request) (any, error) { req := listRoleActionsReq{ token: apiutil.ExtractBearerToken(r), entityID: chi.URLParam(r, d.entityIDTemplate), @@ -204,7 +204,7 @@ func (d Decoder) DecodeListRoleActions(_ context.Context, r *http.Request) (inte return req, nil } -func (d Decoder) DecodeDeleteRoleActions(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeDeleteRoleActions(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -219,7 +219,7 @@ func (d Decoder) DecodeDeleteRoleActions(_ context.Context, r *http.Request) (in return req, nil } -func (d Decoder) DecodeDeleteAllRoleActions(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeDeleteAllRoleActions(_ context.Context, r *http.Request) (any, error) { req := deleteAllRoleActionsReq{ token: apiutil.ExtractBearerToken(r), entityID: chi.URLParam(r, d.entityIDTemplate), @@ -228,7 +228,7 @@ func (d Decoder) DecodeDeleteAllRoleActions(_ context.Context, r *http.Request) return req, nil } -func (d Decoder) DecodeAddRoleMembers(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeAddRoleMembers(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -243,7 +243,7 @@ func (d Decoder) DecodeAddRoleMembers(_ context.Context, r *http.Request) (inter return req, nil } -func (d Decoder) DecodeListRoleMembers(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeListRoleMembers(_ context.Context, r *http.Request) (any, error) { o, err := apiutil.ReadNumQuery[uint64](r, api.OffsetKey, api.DefOffset) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -262,7 +262,7 @@ func (d Decoder) DecodeListRoleMembers(_ context.Context, r *http.Request) (inte return req, nil } -func (d Decoder) DecodeDeleteRoleMembers(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeDeleteRoleMembers(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -277,7 +277,7 @@ func (d Decoder) DecodeDeleteRoleMembers(_ context.Context, r *http.Request) (in return req, nil } -func (d Decoder) DecodeDeleteAllRoleMembers(_ context.Context, r *http.Request) (interface{}, error) { +func (d Decoder) DecodeDeleteAllRoleMembers(_ context.Context, r *http.Request) (any, error) { req := deleteAllRoleMembersReq{ token: apiutil.ExtractBearerToken(r), entityID: chi.URLParam(r, d.entityIDTemplate), diff --git a/pkg/roles/rolemanager/api/endpoints.go b/pkg/roles/rolemanager/api/endpoints.go index a21224d0d..8828fd8d5 100644 --- a/pkg/roles/rolemanager/api/endpoints.go +++ b/pkg/roles/rolemanager/api/endpoints.go @@ -16,7 +16,7 @@ import ( ) func CreateRoleEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(createRoleReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -36,7 +36,7 @@ func CreateRoleEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func ListRolesEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listRolesReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -56,7 +56,7 @@ func ListRolesEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func ListEntityMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listEntityMembersReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -88,7 +88,7 @@ func ListEntityMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func RemoveEntityMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(removeEntityMembersReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -107,7 +107,7 @@ func RemoveEntityMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func ViewRoleEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(viewRoleReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -127,7 +127,7 @@ func ViewRoleEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func UpdateRoleEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateRoleReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -147,7 +147,7 @@ func UpdateRoleEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func DeleteRoleEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(deleteRoleReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -166,7 +166,7 @@ func DeleteRoleEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func ListAvailableActionsEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listAvailableActionsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -186,7 +186,7 @@ func ListAvailableActionsEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func AddRoleActionsEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(addRoleActionsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -206,7 +206,7 @@ func AddRoleActionsEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func ListRoleActionsEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listRoleActionsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -226,7 +226,7 @@ func ListRoleActionsEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func DeleteRoleActionsEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(deleteRoleActionsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -245,7 +245,7 @@ func DeleteRoleActionsEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func DeleteAllRoleActionsEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(deleteAllRoleActionsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -264,7 +264,7 @@ func DeleteAllRoleActionsEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func AddRoleMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(addRoleMembersReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -284,7 +284,7 @@ func AddRoleMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func ListRoleMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listRoleMembersReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -304,7 +304,7 @@ func ListRoleMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func DeleteRoleMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(deleteRoleMembersReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -323,7 +323,7 @@ func DeleteRoleMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { } func DeleteAllRoleMembersEndpoint(svc roles.RoleManager) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(deleteAllRoleMembersReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) diff --git a/pkg/roles/rolemanager/events/consumer/decode.go b/pkg/roles/rolemanager/events/consumer/decode.go index f3b0f5d4d..dfa47d23e 100644 --- a/pkg/roles/rolemanager/events/consumer/decode.go +++ b/pkg/roles/rolemanager/events/consumer/decode.go @@ -31,7 +31,7 @@ const ( layout = "2006-01-02T15:04:05.999999Z" ) -func ToRole(data map[string]interface{}) (roles.Role, error) { +func ToRole(data map[string]any) (roles.Role, error) { var r roles.Role id, ok := data["id"].(string) @@ -85,7 +85,7 @@ func ToRole(data map[string]interface{}) (roles.Role, error) { return r, nil } -func ToStrings(data []interface{}) ([]string, error) { +func ToStrings(data []any) ([]string, error) { var strs []string for _, i := range data { str, ok := i.(string) @@ -97,7 +97,7 @@ func ToStrings(data []interface{}) ([]string, error) { return strs, nil } -func ToRoleProvision(data map[string]interface{}) (roles.RoleProvision, error) { +func ToRoleProvision(data map[string]any) (roles.RoleProvision, error) { var rp roles.RoleProvision r, err := ToRole(data) @@ -108,7 +108,7 @@ func ToRoleProvision(data map[string]interface{}) (roles.RoleProvision, error) { // Following fields of groups are allowed to be empty. - opActs, ok := data["optional_actions"].([]interface{}) + opActs, ok := data["optional_actions"].([]any) if ok { a, err := ToStrings(opActs) if err != nil { @@ -117,7 +117,7 @@ func ToRoleProvision(data map[string]interface{}) (roles.RoleProvision, error) { rp.OptionalActions = a } - opMems, ok := data["optional_members"].([]interface{}) + opMems, ok := data["optional_members"].([]any) if ok { m, err := ToStrings(opMems) if err != nil { @@ -129,10 +129,10 @@ func ToRoleProvision(data map[string]interface{}) (roles.RoleProvision, error) { return rp, nil } -func ToRoleProvisions(data []interface{}) ([]roles.RoleProvision, error) { +func ToRoleProvisions(data []any) ([]roles.RoleProvision, error) { var rps []roles.RoleProvision for _, d := range data { - irp, ok := d.(map[string]interface{}) + irp, ok := d.(map[string]any) if !ok { return []roles.RoleProvision{}, errInvalidRoleProvision } diff --git a/pkg/roles/rolemanager/events/consumer/handler.go b/pkg/roles/rolemanager/events/consumer/handler.go index 95a88e4f7..2cb17db57 100644 --- a/pkg/roles/rolemanager/events/consumer/handler.go +++ b/pkg/roles/rolemanager/events/consumer/handler.go @@ -59,7 +59,7 @@ func NewEventHandler(entityType string, repo roles.Repository) EventHandler { } } -func (es *EventHandler) Handle(ctx context.Context, op interface{}, msg map[string]interface{}) error { +func (es *EventHandler) Handle(ctx context.Context, op any, msg map[string]any) error { switch op { case es.addRole: return es.AddEntityRoleHandler(ctx, msg) @@ -87,7 +87,7 @@ func (es *EventHandler) Handle(ctx context.Context, op interface{}, msg map[stri return nil } -func (es *EventHandler) AddEntityRoleHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) AddEntityRoleHandler(ctx context.Context, data map[string]any) error { rps, err := ToRoleProvision(data) if err != nil { return fmt.Errorf(errAddEntityRoleEvent, es.entityType, err) @@ -101,7 +101,7 @@ func (es *EventHandler) AddEntityRoleHandler(ctx context.Context, data map[strin return nil } -func (es *EventHandler) UpdateEntityRoleHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) UpdateEntityRoleHandler(ctx context.Context, data map[string]any) error { ro, err := ToRole(data) if err != nil { return fmt.Errorf(errUpdateEntityRoleEvent, es.entityType, err) @@ -114,7 +114,7 @@ func (es *EventHandler) UpdateEntityRoleHandler(ctx context.Context, data map[st return nil } -func (es *EventHandler) RemoveEntityRoleHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) RemoveEntityRoleHandler(ctx context.Context, data map[string]any) error { id, ok := data["role_id"].(string) if !ok { return fmt.Errorf(errRemoveEntityRoleEvent, es.entityType, errRoleID) @@ -127,12 +127,12 @@ func (es *EventHandler) RemoveEntityRoleHandler(ctx context.Context, data map[st return nil } -func (es *EventHandler) AddEntityRoleActionsHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) AddEntityRoleActionsHandler(ctx context.Context, data map[string]any) error { id, ok := data["role_id"].(string) if !ok { return fmt.Errorf(errAddEntityRoleActionsEvent, es.entityType, errRoleID) } - iacts, ok := data["actions"].([]interface{}) + iacts, ok := data["actions"].([]any) if !ok { return fmt.Errorf(errAddEntityRoleActionsEvent, es.entityType, errActions) } @@ -148,12 +148,12 @@ func (es *EventHandler) AddEntityRoleActionsHandler(ctx context.Context, data ma return nil } -func (es *EventHandler) RemoveEntityRoleActionsHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) RemoveEntityRoleActionsHandler(ctx context.Context, data map[string]any) error { id, ok := data["role_id"].(string) if !ok { return fmt.Errorf(errAddEntityRoleActionsEvent, es.entityType, errRoleID) } - iacts, ok := data["actions"].([]interface{}) + iacts, ok := data["actions"].([]any) if !ok { return fmt.Errorf(errAddEntityRoleActionsEvent, es.entityType, errActions) } @@ -168,7 +168,7 @@ func (es *EventHandler) RemoveEntityRoleActionsHandler(ctx context.Context, data return nil } -func (es *EventHandler) RemoveAllEntityRoleActionsHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) RemoveAllEntityRoleActionsHandler(ctx context.Context, data map[string]any) error { id, ok := data["role_id"].(string) if !ok { return fmt.Errorf(errRemoveEntityRoleAllActionsEvent, es.entityType, errRoleID) @@ -180,7 +180,7 @@ func (es *EventHandler) RemoveAllEntityRoleActionsHandler(ctx context.Context, d return nil } -func (es *EventHandler) AddEntityRoleMembersHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) AddEntityRoleMembersHandler(ctx context.Context, data map[string]any) error { id, ok := data["role_id"].(string) if !ok { return fmt.Errorf(errAddEntityRoleMembersEvent, es.entityType, errRoleID) @@ -189,7 +189,7 @@ func (es *EventHandler) AddEntityRoleMembersHandler(ctx context.Context, data ma if !ok { return fmt.Errorf(errRemoveEntityRoleAllMembersEvent, es.entityType, errEntityID) } - imems, ok := data["members"].([]interface{}) + imems, ok := data["members"].([]any) if !ok { return fmt.Errorf(errAddEntityRoleMembersEvent, es.entityType, errMembers) } @@ -205,12 +205,12 @@ func (es *EventHandler) AddEntityRoleMembersHandler(ctx context.Context, data ma return nil } -func (es *EventHandler) RemoveEntityRoleMembersHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) RemoveEntityRoleMembersHandler(ctx context.Context, data map[string]any) error { id, ok := data["role_id"].(string) if !ok { return fmt.Errorf(errRemoveEntityRoleMembersEvent, es.entityType, errRoleID) } - imems, ok := data["members"].([]interface{}) + imems, ok := data["members"].([]any) if !ok { return fmt.Errorf(errRemoveEntityRoleMembersEvent, es.entityType, errMembers) } @@ -226,7 +226,7 @@ func (es *EventHandler) RemoveEntityRoleMembersHandler(ctx context.Context, data return nil } -func (es *EventHandler) RemoveAllMembersFromEntityRoleHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) RemoveAllMembersFromEntityRoleHandler(ctx context.Context, data map[string]any) error { id, ok := data["role_id"].(string) if !ok { return fmt.Errorf(errRemoveEntityRoleAllMembersEvent, es.entityType, errRoleID) @@ -238,12 +238,12 @@ func (es *EventHandler) RemoveAllMembersFromEntityRoleHandler(ctx context.Contex return nil } -func (es *EventHandler) RemoveEntityMembersHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) RemoveEntityMembersHandler(ctx context.Context, data map[string]any) error { entityID, ok := data["entity_id"].(string) if !ok { return fmt.Errorf(errRemoveEntityRoleAllMembersEvent, es.entityType, errEntityID) } - imems, ok := data["members"].([]interface{}) + imems, ok := data["members"].([]any) if !ok { return fmt.Errorf(errRemoveEntityRoleMembersEvent, es.entityType, errMembers) } @@ -258,6 +258,6 @@ func (es *EventHandler) RemoveEntityMembersHandler(ctx context.Context, data map return nil } -func (es *EventHandler) RemoveMemberFromAllEntityHandler(ctx context.Context, data map[string]interface{}) error { +func (es *EventHandler) RemoveMemberFromAllEntityHandler(ctx context.Context, data map[string]any) error { return nil } diff --git a/pkg/roles/rolemanager/events/events.go b/pkg/roles/rolemanager/events/events.go index fd641b8e5..3d36a7e8e 100644 --- a/pkg/roles/rolemanager/events/events.go +++ b/pkg/roles/rolemanager/events/events.go @@ -58,8 +58,8 @@ type addRoleEvent struct { requestID string } -func (are addRoleEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (are addRoleEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": are.operationPrefix + AddRole, "id": are.ID, "name": are.Name, @@ -82,8 +82,8 @@ type removeRoleEvent struct { requestID string } -func (rre removeRoleEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rre removeRoleEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rre.operationPrefix + RemoveRole, "entity_id": rre.entityID, "role_id": rre.roleID, @@ -98,8 +98,8 @@ type updateRoleEvent struct { requestID string } -func (ure updateRoleEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (ure updateRoleEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": ure.operationPrefix + UpdateRole, "id": ure.ID, "name": ure.Name, @@ -119,8 +119,8 @@ type retrieveRoleEvent struct { requestID string } -func (rre retrieveRoleEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rre retrieveRoleEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rre.operationPrefix + ViewRole, "id": rre.ID, "name": rre.Name, @@ -142,8 +142,8 @@ type retrieveAllRolesEvent struct { requestID string } -func (rare retrieveAllRolesEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rare retrieveAllRolesEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rare.operationPrefix + ViewAllRole, "entity_id": rare.entityID, "limit": rare.limit, @@ -158,8 +158,8 @@ type listAvailableActionsEvent struct { requestID string } -func (laae listAvailableActionsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (laae listAvailableActionsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": laae.operationPrefix + ListAvailableActions, "request_id": laae.requestID, } @@ -174,8 +174,8 @@ type roleAddActionsEvent struct { requestID string } -func (raae roleAddActionsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (raae roleAddActionsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": raae.operationPrefix + AddRoleActions, "entity_id": raae.entityID, "role_id": raae.roleID, @@ -192,8 +192,8 @@ type roleListActionsEvent struct { requestID string } -func (rlae roleListActionsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rlae roleListActionsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rlae.operationPrefix + ListRoleActions, "entity_id": rlae.entityID, "role_id": rlae.roleID, @@ -211,8 +211,8 @@ type roleCheckActionsExistsEvent struct { requestID string } -func (rcaee roleCheckActionsExistsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rcaee roleCheckActionsExistsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rcaee.operationPrefix + CheckRoleActions, "entity_id": rcaee.entityID, "role_id": rcaee.roleID, @@ -231,8 +231,8 @@ type roleRemoveActionsEvent struct { requestID string } -func (rrae roleRemoveActionsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rrae roleRemoveActionsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rrae.operationPrefix + RemoveRoleActions, "entity_id": rrae.entityID, "role_id": rrae.roleID, @@ -249,8 +249,8 @@ type roleRemoveAllActionsEvent struct { requestID string } -func (rraae roleRemoveAllActionsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rraae roleRemoveAllActionsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rraae.operationPrefix + RemoveAllRoleActions, "entity_id": rraae.entityID, "role_id": rraae.roleID, @@ -267,8 +267,8 @@ type roleAddMembersEvent struct { requestID string } -func (rame roleAddMembersEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rame roleAddMembersEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rame.operationPrefix + AddRoleMembers, "entity_id": rame.entityID, "role_id": rame.roleID, @@ -287,8 +287,8 @@ type roleListMembersEvent struct { requestID string } -func (rlme roleListMembersEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rlme roleListMembersEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rlme.operationPrefix + ListRoleMembers, "entity_id": rlme.entityID, "role_id": rlme.roleID, @@ -307,8 +307,8 @@ type roleCheckMembersExistsEvent struct { requestID string } -func (rcmee roleCheckMembersExistsEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rcmee roleCheckMembersExistsEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rcmee.operationPrefix + CheckRoleMembers, "entity_id": rcmee.entityID, "role_id": rcmee.roleID, @@ -326,8 +326,8 @@ type roleRemoveMembersEvent struct { requestID string } -func (rrme roleRemoveMembersEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rrme roleRemoveMembersEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rrme.operationPrefix + RemoveRoleMembers, "entity_id": rrme.entityID, "role_id": rrme.roleID, @@ -344,8 +344,8 @@ type roleRemoveAllMembersEvent struct { requestID string } -func (rrame roleRemoveAllMembersEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rrame roleRemoveAllMembersEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rrame.operationPrefix + RemoveRoleAllMembers, "entity_id": rrame.entityID, "role_id": rrame.roleID, @@ -362,8 +362,8 @@ type listEntityMembersEvent struct { requestID string } -func (leme listEntityMembersEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (leme listEntityMembersEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": leme.operationPrefix + ListEntityMembers, "entity_id": leme.entityID, "limit": leme.limit, @@ -380,8 +380,8 @@ type removeEntityMembersEvent struct { requestID string } -func (reme removeEntityMembersEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (reme removeEntityMembersEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": reme.operationPrefix + RemoveEntityMembers, "entity_id": reme.entityID, "members": reme.members, @@ -396,8 +396,8 @@ type removeMemberFromAllRolesEvent struct { requestID string } -func (rmare removeMemberFromAllRolesEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (rmare removeMemberFromAllRolesEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": rmare.operationPrefix + RemoveMemberFromAllRoles, "member_id": rmare.memberID, "request_id": rmare.requestID, diff --git a/pkg/roles/rolemanager/middleware/authorization.go b/pkg/roles/rolemanager/middleware/authorization.go index 361a4619b..ae0da793a 100644 --- a/pkg/roles/rolemanager/middleware/authorization.go +++ b/pkg/roles/rolemanager/middleware/authorization.go @@ -500,7 +500,7 @@ func (ram RoleManagerAuthorizationMiddleware) validateMembers(ctx context.Contex } } -func (ram RoleManagerAuthorizationMiddleware) callOut(ctx context.Context, session authn.Session, op string, params map[string]interface{}) error { +func (ram RoleManagerAuthorizationMiddleware) callOut(ctx context.Context, session authn.Session, op string, params map[string]any) error { pl := map[string]any{ "entity_type": ram.entityType, "subject_type": policies.UserType, diff --git a/pkg/sdk/channels_test.go b/pkg/sdk/channels_test.go index 517465aff..4e181c913 100644 --- a/pkg/sdk/channels_test.go +++ b/pkg/sdk/channels_test.go @@ -120,7 +120,7 @@ func TestCreateChannel(t *testing.T) { desc: "create channel that can't be marshalled", channelReq: sdk.Channel{ Name: "test", - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, @@ -305,7 +305,7 @@ func TestCreateChannels(t *testing.T) { ID: generateUUID(t), Name: "channel_1", Route: valid, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, @@ -978,7 +978,7 @@ func TestUpdateChannel(t *testing.T) { channelReq: sdk.Channel{ ID: channel.ID, Name: "test", - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, @@ -1147,7 +1147,7 @@ func TestUpdateChannelTags(t *testing.T) { token: validToken, updateChannelReq: sdk.Channel{ ID: "test", - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, diff --git a/pkg/sdk/clients.go b/pkg/sdk/clients.go index 882b9f6af..ab1698d3e 100644 --- a/pkg/sdk/clients.go +++ b/pkg/sdk/clients.go @@ -33,7 +33,7 @@ type Client struct { DomainID string `json:"domain_id,omitempty"` ParentGroup string `json:"parent_group_id,omitempty"` Credentials ClientCredentials `json:"credentials"` - Metadata map[string]interface{} `json:"metadata,omitempty"` + Metadata map[string]any `json:"metadata,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedBy string `json:"updated_by,omitempty"` diff --git a/pkg/sdk/clients_test.go b/pkg/sdk/clients_test.go index 1bdba1fb8..c20fca134 100644 --- a/pkg/sdk/clients_test.go +++ b/pkg/sdk/clients_test.go @@ -159,7 +159,7 @@ func TestCreateClient(t *testing.T) { token: validToken, createClientReq: sdk.Client{ Name: valid, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ valid: make(chan int), }, }, @@ -273,7 +273,7 @@ func TestCreateClients(t *testing.T) { desc: "create new clients with a request that can't be marshalled", domainID: domainID, token: validToken, - createClientsRequest: []sdk.Client{{Name: "test", Metadata: map[string]interface{}{"test": make(chan int)}}}, + createClientsRequest: []sdk.Client{{Name: "test", Metadata: map[string]any{"test": make(chan int)}}}, svcReq: convertClients(sdkClients...), svcRes: []clients.Client{}, svcErr: nil, @@ -517,7 +517,7 @@ func TestListClients(t *testing.T) { pageMeta: sdk.PageMetadata{ Offset: 0, Limit: 100, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, @@ -739,7 +739,7 @@ func TestUpdateClient(t *testing.T) { sdkClient := generateTestClient(t, false) updatedClient := sdkClient updatedClient.Name = "newName" - updatedClient.Metadata = map[string]interface{}{ + updatedClient.Metadata = map[string]any{ "newKey": "newValue", } updateClientReq := sdk.Client{ @@ -841,7 +841,7 @@ func TestUpdateClient(t *testing.T) { updateClientReq: sdk.Client{ ID: valid, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, @@ -993,7 +993,7 @@ func TestUpdateClientTags(t *testing.T) { token: validToken, updateClientReq: sdk.Client{ ID: valid, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, diff --git a/pkg/sdk/groups_test.go b/pkg/sdk/groups_test.go index 6b0ab6dd7..c6e5ecd15 100644 --- a/pkg/sdk/groups_test.go +++ b/pkg/sdk/groups_test.go @@ -975,7 +975,7 @@ func TestUpdateGroupTags(t *testing.T) { token: validToken, updateGroupReq: sdk.Group{ ID: "test", - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, diff --git a/pkg/sdk/journal_test.go b/pkg/sdk/journal_test.go index 75bd06b75..2cfe933d0 100644 --- a/pkg/sdk/journal_test.go +++ b/pkg/sdk/journal_test.go @@ -283,7 +283,7 @@ func TestRetrieveJournal(t *testing.T) { pageMeta: sdk.PageMetadata{ Offset: 0, Limit: 10, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, }, @@ -317,7 +317,7 @@ func TestRetrieveJournal(t *testing.T) { Operation: "create", OccurredAt: time.Now(), Attributes: validMetadata, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, }}, diff --git a/pkg/sdk/metadata.go b/pkg/sdk/metadata.go index b9341560c..56fb8595a 100644 --- a/pkg/sdk/metadata.go +++ b/pkg/sdk/metadata.go @@ -3,4 +3,4 @@ package sdk -type Metadata map[string]interface{} +type Metadata map[string]any diff --git a/pkg/sdk/users_test.go b/pkg/sdk/users_test.go index 6b13178d3..a3016e7ca 100644 --- a/pkg/sdk/users_test.go +++ b/pkg/sdk/users_test.go @@ -224,7 +224,7 @@ func TestCreateUser(t *testing.T) { FirstName: createSdkUserReq.FirstName, LastName: createSdkUserReq.LastName, Email: createSdkUserReq.Email, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, @@ -997,7 +997,7 @@ func TestUpdateUser(t *testing.T) { token: validToken, updateUserReq: sdk.User{ ID: generateUUID(t), - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, @@ -1158,7 +1158,7 @@ func TestUpdateUserTags(t *testing.T) { token: validToken, updateUserReq: sdk.User{ ID: generateUUID(t), - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, @@ -1762,7 +1762,7 @@ func TestUpdateUserRole(t *testing.T) { token: validToken, updateUserReq: sdk.User{ ID: generateUUID(t), - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, @@ -2090,7 +2090,7 @@ func TestUpdateProfilePicture(t *testing.T) { token: validToken, updateUserReq: sdk.User{ ID: generateUUID(t), - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, diff --git a/pkg/transformers/json/example_test.go b/pkg/transformers/json/example_test.go index afb1a5bd0..b58c32954 100644 --- a/pkg/transformers/json/example_test.go +++ b/pkg/transformers/json/example_test.go @@ -11,7 +11,7 @@ import ( ) func ExampleParseFlat() { - in := map[string]interface{}{ + in := map[string]any{ "key1": "value1", "key2": "value2", "key5/nested1/nested2": "value3", @@ -41,15 +41,15 @@ func ExampleParseFlat() { } func ExampleFlatten() { - in := map[string]interface{}{ + in := map[string]any{ "key1": "value1", "key2": "value2", - "key5": map[string]interface{}{ - "nested1": map[string]interface{}{ + "key5": map[string]any{ + "nested1": map[string]any{ "nested2": "value3", "nested3": "value4", }, - "nested2": map[string]interface{}{ + "nested2": map[string]any{ "nested4": "value5", }, }, diff --git a/pkg/transformers/json/message.go b/pkg/transformers/json/message.go index ab5b1b6da..e05b40fce 100644 --- a/pkg/transformers/json/message.go +++ b/pkg/transformers/json/message.go @@ -4,7 +4,7 @@ package json // Payload represents JSON Message payload. -type Payload map[string]interface{} +type Payload map[string]any // Message represents a JSON messages. type Message struct { diff --git a/pkg/transformers/json/time.go b/pkg/transformers/json/time.go index 7aa6d9c8c..11cb31245 100644 --- a/pkg/transformers/json/time.go +++ b/pkg/transformers/json/time.go @@ -14,7 +14,7 @@ import ( var errUnsupportedFormat = errors.New("unsupported time format") -func parseTimestamp(format string, timestamp interface{}, location string) (time.Time, error) { +func parseTimestamp(format string, timestamp any, location string) (time.Time, error) { switch format { case "unix", "unix_ms", "unix_us", "unix_ns": return parseUnix(format, timestamp) @@ -26,7 +26,7 @@ func parseTimestamp(format string, timestamp interface{}, location string) (time } } -func parseUnix(format string, timestamp interface{}) (time.Time, error) { +func parseUnix(format string, timestamp any) (time.Time, error) { integer, fractional, err := parseComponents(timestamp) if err != nil { return time.Unix(0, 0), err @@ -46,7 +46,7 @@ func parseUnix(format string, timestamp interface{}) (time.Time, error) { } } -func parseComponents(timestamp interface{}) (int64, int64, error) { +func parseComponents(timestamp any) (int64, int64, error) { switch ts := timestamp.(type) { case string: parts := strings.SplitN(ts, ".", 2) @@ -108,7 +108,7 @@ func parseUnixTimeComponents(first, second string) (int64, int64, error) { return integer, fractional, nil } -func parseTime(format string, timestamp interface{}, location string) (time.Time, error) { +func parseTime(format string, timestamp any, location string) (time.Time, error) { switch ts := timestamp.(type) { case string: loc, err := time.LoadLocation(location) diff --git a/pkg/transformers/json/transformer.go b/pkg/transformers/json/transformer.go index 4d949d6db..2dc232fe6 100644 --- a/pkg/transformers/json/transformer.go +++ b/pkg/transformers/json/transformer.go @@ -48,7 +48,7 @@ func New(tfs []TimeField) transformers.Transformer { } // Transform transforms SuperMQ message to a list of JSON messages. -func (ts *transformerService) Transform(msg *messaging.Message) (interface{}, error) { +func (ts *transformerService) Transform(msg *messaging.Message) (any, error) { ret := Message{ Publisher: msg.GetPublisher(), Created: msg.GetCreated(), @@ -67,13 +67,13 @@ func (ts *transformerService) Transform(msg *messaging.Message) (interface{}, er } format := subs[len(subs)-1] - var payload interface{} + var payload any if err := json.Unmarshal(msg.GetPayload(), &payload); err != nil { return nil, errors.Wrap(ErrTransform, err) } switch p := payload.(type) { - case map[string]interface{}: + case map[string]any: ret.Payload = p // Apply timestamp transformation rules depending on key/unit pairs @@ -86,11 +86,11 @@ func (ts *transformerService) Transform(msg *messaging.Message) (interface{}, er } return Messages{[]Message{ret}, format}, nil - case []interface{}: + case []any: res := []Message{} // Make an array of messages from the root array. for _, val := range p { - v, ok := val.(map[string]interface{}) + v, ok := val.(map[string]any) if !ok { return nil, errors.Wrap(ErrTransform, errInvalidNestedJSON) } @@ -117,9 +117,9 @@ func (ts *transformerService) Transform(msg *messaging.Message) (interface{}, er // ParseFlat receives flat map that represents complex JSON objects and returns // the corresponding complex JSON object with nested maps. It's the opposite // of the Flatten function. -func ParseFlat(flat interface{}) interface{} { - msg := make(map[string]interface{}) - if v, ok := flat.(map[string]interface{}); ok { +func ParseFlat(flat any) any { + msg := make(map[string]any) + if v, ok := flat.(map[string]any); ok { for key, value := range v { if value == nil { continue @@ -133,13 +133,13 @@ func ParseFlat(flat interface{}) interface{} { current := msg for i, k := range subKeys { if _, ok := current[k]; !ok { - current[k] = make(map[string]interface{}) + current[k] = make(map[string]any) } if i == n-1 { current[k] = value break } - current = current[k].(map[string]interface{}) + current = current[k].(map[string]any) } } } @@ -147,11 +147,11 @@ func ParseFlat(flat interface{}) interface{} { } // Flatten makes nested maps flat using composite keys created by concatenation of the nested keys. -func Flatten(m map[string]interface{}) (map[string]interface{}, error) { - return flatten("", make(map[string]interface{}), m) +func Flatten(m map[string]any) (map[string]any, error) { + return flatten("", make(map[string]any), m) } -func flatten(prefix string, m, m1 map[string]interface{}) (map[string]interface{}, error) { +func flatten(prefix string, m, m1 map[string]any) (map[string]any, error) { for k, v := range m1 { if strings.Contains(k, sep) { return nil, ErrInvalidKey @@ -162,7 +162,7 @@ func flatten(prefix string, m, m1 map[string]interface{}) (map[string]interface{ } } switch val := v.(type) { - case map[string]interface{}: + case map[string]any: var err error m, err = flatten(prefix+k+sep, m, val) if err != nil { @@ -175,7 +175,7 @@ func flatten(prefix string, m, m1 map[string]interface{}) (map[string]interface{ return m, nil } -func (ts *transformerService) transformTimeField(payload map[string]interface{}) (int64, error) { +func (ts *transformerService) transformTimeField(payload map[string]any) (int64, error) { if len(ts.timeFields) == 0 { return 0, nil } diff --git a/pkg/transformers/json/transformer_test.go b/pkg/transformers/json/transformer_test.go index a7e59388a..478293273 100644 --- a/pkg/transformers/json/transformer_test.go +++ b/pkg/transformers/json/transformer_test.go @@ -105,11 +105,11 @@ func TestTransformJSON(t *testing.T) { Publisher: msg.Publisher, Protocol: msg.Protocol, Created: msg.Created, - Payload: map[string]interface{}{ + Payload: map[string]any{ "key1": "val1", "key2": float64(123), "key3": "val3", - "key4": map[string]interface{}{ + "key4": map[string]any{ "key5": "val5", }, }, @@ -126,12 +126,12 @@ func TestTransformJSON(t *testing.T) { Publisher: msg.Publisher, Protocol: msg.Protocol, Created: int64(1638310819000000000), - Payload: map[string]interface{}{ + Payload: map[string]any{ "custom_ts_key": "1638310819", "key1": "val1", "key2": float64(123), "key3": "val3", - "key4": map[string]interface{}{ + "key4": map[string]any{ "key5": "val5", }, }, @@ -148,12 +148,12 @@ func TestTransformJSON(t *testing.T) { Publisher: msg.Publisher, Protocol: msg.Protocol, Created: int64(1638310819000000000), - Payload: map[string]interface{}{ + Payload: map[string]any{ "custom_ts_micro_key": "1638310819000000", "key1": "val1", "key2": float64(123), "key3": "val3", - "key4": map[string]interface{}{ + "key4": map[string]any{ "key5": "val5", }, }, @@ -170,11 +170,11 @@ func TestTransformJSON(t *testing.T) { Publisher: msg.Publisher, Protocol: msg.Protocol, Created: msg.Created, - Payload: map[string]interface{}{ + Payload: map[string]any{ "key1": "val1", "key2": float64(123), "keylist3": "val3", - "key4": map[string]interface{}{ + "key4": map[string]any{ "key5": "val5", }, }, @@ -185,11 +185,11 @@ func TestTransformJSON(t *testing.T) { Publisher: msg.Publisher, Protocol: msg.Protocol, Created: msg.Created, - Payload: map[string]interface{}{ + Payload: map[string]any{ "key1": "val1", "key2": float64(123), "key3": "val3", - "key4": map[string]interface{}{ + "key4": map[string]any{ "key5": "val5", }, }, @@ -201,7 +201,7 @@ func TestTransformJSON(t *testing.T) { cases := []struct { desc string msg *messaging.Message - json interface{} + json any err error }{ { diff --git a/pkg/transformers/senml/transformer.go b/pkg/transformers/senml/transformer.go index 36bd8580a..efc37d61c 100644 --- a/pkg/transformers/senml/transformer.go +++ b/pkg/transformers/senml/transformer.go @@ -45,7 +45,7 @@ func New(contentFormat string) transformers.Transformer { } } -func (t transformer) Transform(msg *messaging.Message) (interface{}, error) { +func (t transformer) Transform(msg *messaging.Message) (any, error) { raw, err := senml.Decode(msg.GetPayload(), t.format) if err != nil { return nil, errors.Wrap(errDecode, err) diff --git a/pkg/transformers/senml/transformer_test.go b/pkg/transformers/senml/transformer_test.go index 96e4f764c..f0a3ec870 100644 --- a/pkg/transformers/senml/transformer_test.go +++ b/pkg/transformers/senml/transformer_test.go @@ -54,7 +54,7 @@ func TestTransformJSON(t *testing.T) { cases := []struct { desc string msg *messaging.Message - msgs interface{} + msgs any err error }{ { @@ -126,7 +126,7 @@ func TestTransformCBOR(t *testing.T) { cases := []struct { desc string msg *messaging.Message - msgs interface{} + msgs any err error }{ { diff --git a/pkg/transformers/transformer.go b/pkg/transformers/transformer.go index 9364bc9d0..06303f65f 100644 --- a/pkg/transformers/transformer.go +++ b/pkg/transformers/transformer.go @@ -8,7 +8,7 @@ import "github.com/absmach/supermq/pkg/messaging" // Transformer specifies API form Message transformer. type Transformer interface { // Transform SuperMQ message to any other format. - Transform(msg *messaging.Message) (interface{}, error) + Transform(msg *messaging.Message) (any, error) } type number interface { diff --git a/readers/messages.go b/readers/messages.go index eb14ebeb0..1d9662831 100644 --- a/readers/messages.go +++ b/readers/messages.go @@ -29,7 +29,7 @@ type MessageRepository interface { } // Message represents any message format. -type Message interface{} +type Message any // MessagesPage contains page related metadata as well as list of messages that // belong to this page. @@ -60,7 +60,7 @@ type PageMetadata struct { } // ParseValueComparator convert comparison operator keys into mathematic anotation. -func ParseValueComparator(query map[string]interface{}) string { +func ParseValueComparator(query map[string]any) string { comparator := "=" val, ok := query["comparator"] if ok { diff --git a/users/api/endpoint_test.go b/users/api/endpoint_test.go index 41a5f6e4a..23bb00ef2 100644 --- a/users/api/endpoint_test.go +++ b/users/api/endpoint_test.go @@ -100,7 +100,7 @@ func newUsersServer() (*httptest.Server, *mocks.Service, *authnmocks.Authenticat return httptest.NewServer(mux), svc, authn } -func toJSON(data interface{}) string { +func toJSON(data any) string { jsonData, err := json.Marshal(data) if err != nil { return "" @@ -165,7 +165,7 @@ func TestRegister(t *testing.T) { Credentials: users.Credentials{ Secret: "12345678", }, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "test": make(chan int), }, }, diff --git a/users/api/endpoints.go b/users/api/endpoints.go index a75be2fb4..c047646ae 100644 --- a/users/api/endpoints.go +++ b/users/api/endpoints.go @@ -16,7 +16,7 @@ import ( ) func registrationEndpoint(svc users.Service, selfRegister bool) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(createUserReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -44,7 +44,7 @@ func registrationEndpoint(svc users.Service, selfRegister bool) endpoint.Endpoin } func viewEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(viewUserReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -64,7 +64,7 @@ func viewEndpoint(svc users.Service) endpoint.Endpoint { } func viewProfileEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { session, ok := ctx.Value(api.SessionKey).(authn.Session) if !ok { return nil, svcerr.ErrAuthentication @@ -79,7 +79,7 @@ func viewProfileEndpoint(svc users.Service) endpoint.Endpoint { } func listUsersEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(listUsersReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -128,7 +128,7 @@ func listUsersEndpoint(svc users.Service) endpoint.Endpoint { } func searchUsersEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(searchUsersReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -166,7 +166,7 @@ func searchUsersEndpoint(svc users.Service) endpoint.Endpoint { } func updateEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateUserReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -193,7 +193,7 @@ func updateEndpoint(svc users.Service) endpoint.Endpoint { } func updateTagsEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateUserTagsReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -218,7 +218,7 @@ func updateTagsEndpoint(svc users.Service) endpoint.Endpoint { } func updateEmailEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateEmailReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -249,7 +249,7 @@ func updateEmailEndpoint(svc users.Service) endpoint.Endpoint { // enter new password, when form is submitted token and new password // must be sent as PUT request to 'password/reset' passwordResetEndpoint. func passwordResetRequestEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(passResetReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -267,7 +267,7 @@ func passwordResetRequestEndpoint(svc users.Service) endpoint.Endpoint { // When user clicks on a link in email finally ends on this endpoint as explained in // the comment above. func passwordResetEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(resetTokenReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -286,7 +286,7 @@ func passwordResetEndpoint(svc users.Service) endpoint.Endpoint { } func updateSecretEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateUserSecretReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -306,7 +306,7 @@ func updateSecretEndpoint(svc users.Service) endpoint.Endpoint { } func updateUsernameEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateUsernameReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -327,7 +327,7 @@ func updateUsernameEndpoint(svc users.Service) endpoint.Endpoint { } func updateProfilePictureEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateProfilePictureReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -352,7 +352,7 @@ func updateProfilePictureEndpoint(svc users.Service) endpoint.Endpoint { } func updateRoleEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(updateUserRoleReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -378,7 +378,7 @@ func updateRoleEndpoint(svc users.Service) endpoint.Endpoint { } func issueTokenEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(loginUserReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -398,7 +398,7 @@ func issueTokenEndpoint(svc users.Service) endpoint.Endpoint { } func refreshTokenEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(tokenReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -423,7 +423,7 @@ func refreshTokenEndpoint(svc users.Service) endpoint.Endpoint { } func enableEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(changeUserStatusReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -444,7 +444,7 @@ func enableEndpoint(svc users.Service) endpoint.Endpoint { } func disableEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(changeUserStatusReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -465,7 +465,7 @@ func disableEndpoint(svc users.Service) endpoint.Endpoint { } func deleteEndpoint(svc users.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request any) (any, error) { req := request.(changeUserStatusReq) if err := req.validate(); err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) diff --git a/users/api/users.go b/users/api/users.go index 5aba8fffc..bd9dde2bd 100644 --- a/users/api/users.go +++ b/users/api/users.go @@ -196,7 +196,7 @@ func usersHandler(svc users.Service, authn smqauthn.Authentication, tokenClient return r } -func decodeViewUser(_ context.Context, r *http.Request) (interface{}, error) { +func decodeViewUser(_ context.Context, r *http.Request) (any, error) { req := viewUserReq{ id: chi.URLParam(r, "id"), } @@ -204,11 +204,11 @@ func decodeViewUser(_ context.Context, r *http.Request) (interface{}, error) { return req, nil } -func decodeViewProfile(_ context.Context, r *http.Request) (interface{}, error) { +func decodeViewProfile(_ context.Context, r *http.Request) (any, error) { return nil, nil } -func decodeListUsers(_ context.Context, r *http.Request) (interface{}, error) { +func decodeListUsers(_ context.Context, r *http.Request) (any, error) { s, err := apiutil.ReadStringQuery(r, api.StatusKey, api.DefUserStatus) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -287,7 +287,7 @@ func decodeListUsers(_ context.Context, r *http.Request) (interface{}, error) { return req, nil } -func decodeSearchUsers(_ context.Context, r *http.Request) (interface{}, error) { +func decodeSearchUsers(_ context.Context, r *http.Request) (any, error) { o, err := apiutil.ReadNumQuery[uint64](r, api.OffsetKey, api.DefOffset) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -342,7 +342,7 @@ func decodeSearchUsers(_ context.Context, r *http.Request) (interface{}, error) return req, nil } -func decodeUpdateUser(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateUser(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -357,7 +357,7 @@ func decodeUpdateUser(_ context.Context, r *http.Request) (interface{}, error) { return req, nil } -func decodeUpdateUserTags(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateUserTags(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -372,7 +372,7 @@ func decodeUpdateUserTags(_ context.Context, r *http.Request) (interface{}, erro return req, nil } -func decodeUpdateUserEmail(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateUserEmail(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -387,7 +387,7 @@ func decodeUpdateUserEmail(_ context.Context, r *http.Request) (interface{}, err return req, nil } -func decodeUpdateUserSecret(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateUserSecret(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -400,7 +400,7 @@ func decodeUpdateUserSecret(_ context.Context, r *http.Request) (interface{}, er return req, nil } -func decodeUpdateUsername(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateUsername(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -415,7 +415,7 @@ func decodeUpdateUsername(_ context.Context, r *http.Request) (interface{}, erro return req, nil } -func decodeUpdateUserProfilePicture(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateUserProfilePicture(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -431,7 +431,7 @@ func decodeUpdateUserProfilePicture(_ context.Context, r *http.Request) (interfa return req, nil } -func decodePasswordResetRequest(_ context.Context, r *http.Request) (interface{}, error) { +func decodePasswordResetRequest(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, apiutil.ErrUnsupportedContentType } @@ -445,7 +445,7 @@ func decodePasswordResetRequest(_ context.Context, r *http.Request) (interface{} return req, nil } -func decodePasswordReset(_ context.Context, r *http.Request) (interface{}, error) { +func decodePasswordReset(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -458,7 +458,7 @@ func decodePasswordReset(_ context.Context, r *http.Request) (interface{}, error return req, nil } -func decodeUpdateUserRole(_ context.Context, r *http.Request) (interface{}, error) { +func decodeUpdateUserRole(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -474,7 +474,7 @@ func decodeUpdateUserRole(_ context.Context, r *http.Request) (interface{}, erro return req, err } -func decodeCredentials(_ context.Context, r *http.Request) (interface{}, error) { +func decodeCredentials(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -487,7 +487,7 @@ func decodeCredentials(_ context.Context, r *http.Request) (interface{}, error) return req, nil } -func decodeRefreshToken(_ context.Context, r *http.Request) (interface{}, error) { +func decodeRefreshToken(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -496,7 +496,7 @@ func decodeRefreshToken(_ context.Context, r *http.Request) (interface{}, error) return req, nil } -func decodeCreateUserReq(_ context.Context, r *http.Request) (interface{}, error) { +func decodeCreateUserReq(_ context.Context, r *http.Request) (any, error) { if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) { return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType) } @@ -509,7 +509,7 @@ func decodeCreateUserReq(_ context.Context, r *http.Request) (interface{}, error return req, nil } -func decodeChangeUserStatus(_ context.Context, r *http.Request) (interface{}, error) { +func decodeChangeUserStatus(_ context.Context, r *http.Request) (any, error) { req := changeUserStatusReq{ id: chi.URLParam(r, "id"), } diff --git a/users/events/events.go b/users/events/events.go index 8b69dccf2..db35f28fb 100644 --- a/users/events/events.go +++ b/users/events/events.go @@ -66,8 +66,8 @@ type createUserEvent struct { requestID string } -func (uce createUserEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (uce createUserEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": userCreate, "id": uce.ID, "status": uce.Status.String(), @@ -106,8 +106,8 @@ type updateUserEvent struct { requestID string } -func (uce updateUserEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (uce updateUserEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": uce.operation, "updated_at": uce.UpdatedAt, "updated_by": uce.UpdatedBy, @@ -153,8 +153,8 @@ type updateUsernameEvent struct { requestID string } -func (une updateUsernameEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (une updateUsernameEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": userUpdateUsername, "updated_at": une.UpdatedAt, "updated_by": une.UpdatedBy, @@ -185,8 +185,8 @@ type updateProfilePictureEvent struct { requestID string } -func (req updateProfilePictureEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (req updateProfilePictureEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": userUpdateProfilePicture, "updated_at": req.UpdatedAt, "updated_by": req.UpdatedBy, @@ -215,8 +215,8 @@ type changeUserStatusEvent struct { requestID string } -func (rce changeUserStatusEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (rce changeUserStatusEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": rce.operation, "id": rce.id, "status": rce.status, @@ -234,8 +234,8 @@ type viewUserEvent struct { requestID string } -func (vue viewUserEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (vue viewUserEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": userView, "id": vue.ID, "token_type": vue.Type.String(), @@ -283,8 +283,8 @@ type viewProfileEvent struct { requestID string } -func (vpe viewProfileEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (vpe viewProfileEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": profileView, "id": vpe.ID, "token_type": vpe.Type.String(), @@ -329,8 +329,8 @@ type listUserEvent struct { requestID string } -func (lue listUserEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (lue listUserEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": userList, "total": lue.Total, "offset": lue.Offset, @@ -382,8 +382,8 @@ type searchUserEvent struct { requestID string } -func (sce searchUserEvent) Encode() (map[string]interface{}, error) { - val := map[string]interface{}{ +func (sce searchUserEvent) Encode() (map[string]any, error) { + val := map[string]any{ "operation": userSearch, "total": sce.Total, "offset": sce.Offset, @@ -414,8 +414,8 @@ type identifyUserEvent struct { requestID string } -func (ise identifyUserEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (ise identifyUserEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": userIdentify, "id": ise.userID, "request_id": ise.requestID, @@ -428,8 +428,8 @@ type generateResetTokenEvent struct { requestID string } -func (req generateResetTokenEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (req generateResetTokenEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": generateResetToken, "email": req.email, "host": req.host, @@ -442,8 +442,8 @@ type issueTokenEvent struct { requestID string } -func (ite issueTokenEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (ite issueTokenEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": issueToken, "username": ite.username, "request_id": ite.requestID, @@ -454,8 +454,8 @@ type refreshTokenEvent struct { requestID string } -func (rte refreshTokenEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (rte refreshTokenEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": refreshToken, "request_id": rte.requestID, }, nil @@ -465,8 +465,8 @@ type resetSecretEvent struct { requestID string } -func (rse resetSecretEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (rse resetSecretEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": resetSecret, "request_id": rse.requestID, }, nil @@ -479,8 +479,8 @@ type sendPasswordResetEvent struct { requestID string } -func (req sendPasswordResetEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (req sendPasswordResetEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": sendPasswordReset, "host": req.host, "email": req.email, @@ -494,8 +494,8 @@ type oauthCallbackEvent struct { requestID string } -func (oce oauthCallbackEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (oce oauthCallbackEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": oauthCallback, "user_id": oce.userID, "request_id": oce.requestID, @@ -508,8 +508,8 @@ type deleteUserEvent struct { requestID string } -func (dce deleteUserEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (dce deleteUserEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": deleteUser, "id": dce.id, "token_type": dce.Type.String(), @@ -525,8 +525,8 @@ type addUserPolicyEvent struct { requestID string } -func (req addUserPolicyEvent) Encode() (map[string]interface{}, error) { - return map[string]interface{}{ +func (req addUserPolicyEvent) Encode() (map[string]any, error) { + return map[string]any{ "operation": addClientPolicy, "id": req.id, "role": req.role, diff --git a/users/postgres/users_test.go b/users/postgres/users_test.go index 6d1c1b06c..471524aa6 100644 --- a/users/postgres/users_test.go +++ b/users/postgres/users_test.go @@ -168,7 +168,7 @@ func TestUsersSave(t *testing.T) { Username: username, Secret: password, }, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, }, @@ -325,7 +325,7 @@ func TestRetrieveAll(t *testing.T) { Tags: []string{"tag1"}, } if i%50 == 0 { - user.Metadata = map[string]interface{}{ + user.Metadata = map[string]any{ "key": "value", } user.Role = users.AdminRole @@ -615,7 +615,7 @@ func TestRetrieveAll(t *testing.T) { { desc: "retrieve with metadata", pageMeta: users.Page{ - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": "value", }, Offset: 0, @@ -636,7 +636,7 @@ func TestRetrieveAll(t *testing.T) { { desc: "retrieve with invalid metadata", pageMeta: users.Page{ - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": "value1", }, Offset: 0, @@ -1818,7 +1818,7 @@ func TestRetrieveByIDs(t *testing.T) { page: users.Page{ Offset: 0, Limit: 10, - Metadata: map[string]interface{}{ + Metadata: map[string]any{ "key": make(chan int), }, IDs: getIDs(items[0:20]), diff --git a/users/users.go b/users/users.go index 2f26d6386..cfa5b9ecd 100644 --- a/users/users.go +++ b/users/users.go @@ -42,7 +42,7 @@ type UsersPage struct { } // Metadata represents arbitrary JSON. -type Metadata map[string]interface{} +type Metadata map[string]any type UserReq struct { FirstName *string `json:"first_name,omitempty"`