NOISSUE - Replace interface{} with any (#285)

Signed-off-by: dusan <borovcanindusan1@gmail.com>
This commit is contained in:
Dušan Borovčanin
2025-08-26 13:26:32 +02:00
committed by GitHub
parent 21494525fe
commit 60e256c267
80 changed files with 369 additions and 369 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ const SeverityMax uint8 = 100
var ErrInvalidSeverity = errors.New("invalid severity. Must be between 0 and 100")
type Metadata map[string]interface{}
type Metadata map[string]any
// Alarm represents an alarm instance.
type Alarm struct {
+4 -4
View File
@@ -16,7 +16,7 @@ import (
)
func updateAlarmEndpoint(svc alarms.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(alarmReq)
if err := req.validate(); err != nil {
return alarmRes{}, errors.Wrap(apiutil.ErrValidation, err)
@@ -39,7 +39,7 @@ func updateAlarmEndpoint(svc alarms.Service) endpoint.Endpoint {
}
func viewAlarmEndpoint(svc alarms.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(alarmReq)
if err := req.validate(); err != nil {
return alarmRes{}, errors.Wrap(apiutil.ErrValidation, err)
@@ -62,7 +62,7 @@ func viewAlarmEndpoint(svc alarms.Service) endpoint.Endpoint {
}
func listAlarmsEndpoint(svc alarms.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(listAlarmsReq)
if err := req.validate(); err != nil {
return alarmsPageRes{}, errors.Wrap(apiutil.ErrValidation, err)
@@ -85,7 +85,7 @@ func listAlarmsEndpoint(svc alarms.Service) endpoint.Endpoint {
}
func deleteAlarmEndpoint(svc alarms.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(alarmReq)
if err := req.validate(); err != nil {
return alarmRes{}, errors.Wrap(apiutil.ErrValidation, err)
+3 -3
View File
@@ -71,7 +71,7 @@ func MakeHandler(svc alarms.Service, logger *slog.Logger, idp supermq.IDProvider
return mux
}
func decodeListAlarmsReq(_ context.Context, r *http.Request) (interface{}, error) {
func decodeListAlarmsReq(_ context.Context, r *http.Request) (any, error) {
offset, err := apiutil.ReadNumQuery[uint64](r, api.OffsetKey, api.DefOffset)
if err != nil {
return listAlarmsReq{}, errors.Wrap(apiutil.ErrValidation, err)
@@ -185,7 +185,7 @@ func decodeListAlarmsReq(_ context.Context, r *http.Request) (interface{}, error
}, nil
}
func decodeAlarmReq(_ context.Context, r *http.Request) (interface{}, error) {
func decodeAlarmReq(_ context.Context, r *http.Request) (any, error) {
return alarmReq{
Alarm: alarms.Alarm{
ID: chi.URLParam(r, "alarmID"),
@@ -193,7 +193,7 @@ func decodeAlarmReq(_ context.Context, r *http.Request) (interface{}, error) {
}, nil
}
func decodeUpdateAlarmReq(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateAlarmReq(_ context.Context, r *http.Request) (any, error) {
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return alarmReq{}, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}
+3 -3
View File
@@ -156,7 +156,7 @@ func (r *repository) UpdateAlarm(ctx context.Context, alarm alarms.Alarm) (alarm
func (r *repository) ViewAlarm(ctx context.Context, alarmID, domainID string) (alarms.Alarm, error) {
query := `SELECT * FROM alarms WHERE id = :id AND domain_id = :domain_id;`
row, err := r.db.NamedQueryContext(ctx, query, map[string]interface{}{
row, err := r.db.NamedQueryContext(ctx, query, map[string]any{
"id": alarmID, "domain_id": domainID,
})
if err != nil {
@@ -245,7 +245,7 @@ func (r *repository) ListAlarms(ctx context.Context, pm alarms.PageMetadata) (al
func (r *repository) DeleteAlarm(ctx context.Context, id string) error {
query := `DELETE FROM alarms WHERE id = :id;`
result, err := r.db.NamedExecContext(ctx, query, map[string]interface{}{"id": id})
result, err := r.db.NamedExecContext(ctx, query, map[string]any{"id": id})
if err != nil {
return errors.Wrap(repoerr.ErrRemoveEntity, err)
}
@@ -403,7 +403,7 @@ func toAlarm(dbr dbAlarm) (alarms.Alarm, error) {
resolvedAt = dbr.ResolvedAt.Time
}
var metadata map[string]interface{}
var metadata map[string]any
if len(dbr.Metadata) > 0 {
err := json.Unmarshal(dbr.Metadata, &metadata)
if err != nil {
+9 -9
View File
@@ -48,7 +48,7 @@ func TestCreateAlarm(t *testing.T) {
Status: 0,
AssigneeID: generateUUID(&testing.T{}),
CreatedAt: time.Now().Local(),
Metadata: map[string]interface{}{
Metadata: map[string]any{
"key": "value",
},
}
@@ -85,7 +85,7 @@ func TestCreateAlarm(t *testing.T) {
AssigneeID: generateUUID(&testing.T{}),
CreatedAt: time.Now().Local(),
Metadata: map[string]interface{}{
Metadata: map[string]any{
"key": "value",
},
},
@@ -108,7 +108,7 @@ func TestCreateAlarm(t *testing.T) {
AssigneeID: generateUUID(&testing.T{}),
CreatedAt: time.Now().Local(),
Metadata: map[string]interface{}{
Metadata: map[string]any{
"key": make(chan int),
},
},
@@ -166,7 +166,7 @@ func TestUpdateAlarm(t *testing.T) {
Status: 0,
AssigneeID: generateUUID(&testing.T{}),
CreatedAt: time.Now().Local(),
Metadata: map[string]interface{}{
Metadata: map[string]any{
"key": "value",
},
}
@@ -190,7 +190,7 @@ func TestUpdateAlarm(t *testing.T) {
UpdatedBy: generateUUID(&testing.T{}),
ResolvedAt: time.Now().Local(),
ResolvedBy: generateUUID(&testing.T{}),
Metadata: map[string]interface{}{
Metadata: map[string]any{
"key": "value",
},
},
@@ -212,7 +212,7 @@ func TestUpdateAlarm(t *testing.T) {
DomainID: generateUUID(&testing.T{}),
AssigneeID: strings.Repeat("a", 40),
CreatedAt: time.Now().Local(),
Metadata: map[string]interface{}{
Metadata: map[string]any{
"key": "value",
},
},
@@ -265,7 +265,7 @@ func TestViewAlarm(t *testing.T) {
Status: 0,
AssigneeID: generateUUID(&testing.T{}),
CreatedAt: time.Now().Local(),
Metadata: map[string]interface{}{
Metadata: map[string]any{
"key": "value",
},
}
@@ -335,7 +335,7 @@ func TestListAlarms(t *testing.T) {
Status: 0,
AssigneeID: generateUUID(&testing.T{}),
CreatedAt: time.Now().Local(),
Metadata: map[string]interface{}{
Metadata: map[string]any{
"key": "value",
},
}
@@ -430,7 +430,7 @@ func TestDeleteAlarm(t *testing.T) {
Status: 0,
AssigneeID: generateUUID(&testing.T{}),
CreatedAt: time.Now().Local(),
Metadata: map[string]interface{}{
Metadata: map[string]any{
"key": "value",
},
}
+9 -9
View File
@@ -16,7 +16,7 @@ import (
)
func addEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(addReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
@@ -59,7 +59,7 @@ func addEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}
func updateCertEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(updateCertReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
@@ -87,7 +87,7 @@ func updateCertEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}
func viewEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(entityReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
@@ -128,7 +128,7 @@ func viewEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}
func updateEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(updateReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
@@ -159,7 +159,7 @@ func updateEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}
func updateConnEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(updateConnReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
@@ -184,7 +184,7 @@ func updateConnEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}
func listEndpoint(svc bootstrap.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)
@@ -234,7 +234,7 @@ func listEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}
func removeEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(entityReq)
if err := req.validate(); err != nil {
return removeRes{}, errors.Wrap(apiutil.ErrValidation, err)
@@ -254,7 +254,7 @@ func removeEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}
func bootstrapEndpoint(svc bootstrap.Service, reader bootstrap.ConfigReader, secure bool) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(bootstrapReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
@@ -270,7 +270,7 @@ func bootstrapEndpoint(svc bootstrap.Service, reader bootstrap.ConfigReader, sec
}
func stateEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(changeStateReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
+3 -3
View File
@@ -50,7 +50,7 @@ const (
var (
encKey = []byte("1234567891011121")
metadata = map[string]interface{}{"meta": "data"}
metadata = map[string]any{"meta": "data"}
addExternalID = testsutil.GenerateUUID(&testing.T{})
addExternalKey = testsutil.GenerateUUID(&testing.T{})
addClientID = testsutil.GenerateUUID(&testing.T{})
@@ -184,7 +184,7 @@ func newBootstrapServer() (*httptest.Server, *mocks.Service, *authnmocks.Authent
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 ""
@@ -1396,7 +1396,7 @@ func TestChangeState(t *testing.T) {
type channel struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
Metadata any `json:"metadata,omitempty"`
}
type config struct {
+1 -1
View File
@@ -63,7 +63,7 @@ func (res configRes) Empty() bool {
type channelRes struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
Metadata any `json:"metadata,omitempty"`
}
type viewRes struct {
+9 -9
View File
@@ -128,7 +128,7 @@ func MakeHandler(svc bootstrap.Service, authn smqauthn.Authentication, reader bo
return r
}
func decodeAddRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeAddRequest(_ context.Context, r *http.Request) (any, error) {
if !strings.Contains(r.Header.Get("Content-Type"), contentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}
@@ -143,7 +143,7 @@ func decodeAddRequest(_ context.Context, r *http.Request) (interface{}, error) {
return req, nil
}
func decodeUpdateRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateRequest(_ context.Context, r *http.Request) (any, error) {
if !strings.Contains(r.Header.Get("Content-Type"), contentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}
@@ -158,7 +158,7 @@ func decodeUpdateRequest(_ context.Context, r *http.Request) (interface{}, error
return req, nil
}
func decodeUpdateCertRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateCertRequest(_ context.Context, r *http.Request) (any, error) {
if !strings.Contains(r.Header.Get("Content-Type"), contentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}
@@ -173,7 +173,7 @@ func decodeUpdateCertRequest(_ context.Context, r *http.Request) (interface{}, e
return req, nil
}
func decodeUpdateConnRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateConnRequest(_ context.Context, r *http.Request) (any, error) {
if !strings.Contains(r.Header.Get("Content-Type"), contentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}
@@ -189,7 +189,7 @@ func decodeUpdateConnRequest(_ context.Context, r *http.Request) (interface{}, e
return req, nil
}
func decodeListRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeListRequest(_ context.Context, r *http.Request) (any, error) {
o, err := apiutil.ReadNumQuery[uint64](r, offsetKey, defOffset)
if err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
@@ -214,7 +214,7 @@ func decodeListRequest(_ context.Context, r *http.Request) (interface{}, error)
return req, nil
}
func decodeBootstrapRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeBootstrapRequest(_ context.Context, r *http.Request) (any, error) {
req := bootstrapReq{
id: chi.URLParam(r, "externalID"),
key: apiutil.ExtractClientSecret(r),
@@ -223,7 +223,7 @@ func decodeBootstrapRequest(_ context.Context, r *http.Request) (interface{}, er
return req, nil
}
func decodeStateRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeStateRequest(_ context.Context, r *http.Request) (any, error) {
if !strings.Contains(r.Header.Get("Content-Type"), contentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}
@@ -239,7 +239,7 @@ func decodeStateRequest(_ context.Context, r *http.Request) (interface{}, error)
return req, nil
}
func decodeEntityRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeEntityRequest(_ context.Context, r *http.Request) (any, error) {
req := entityReq{
id: chi.URLParam(r, "configID"),
}
@@ -247,7 +247,7 @@ func decodeEntityRequest(_ context.Context, r *http.Request) (interface{}, error
return req, nil
}
func encodeSecureRes(_ context.Context, w http.ResponseWriter, response interface{}) error {
func encodeSecureRes(_ context.Context, w http.ResponseWriter, response any) error {
w.Header().Set("Content-Type", byteContentType)
w.WriteHeader(http.StatusOK)
if b, ok := response.([]byte); ok {
+1 -1
View File
@@ -34,7 +34,7 @@ type Config struct {
type Channel struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
DomainID string `json:"domain_id"`
Parent string `json:"parent_id,omitempty"`
Description string `json:"description,omitempty"`
+1 -1
View File
@@ -12,7 +12,7 @@ type removeEvent struct {
type updateChannelEvent struct {
id string
name string
metadata map[string]interface{}
metadata map[string]any
updatedAt time.Time
updatedBy string
}
+6 -6
View File
@@ -89,14 +89,14 @@ func (es *eventHandler) Handle(ctx context.Context, event events.Event) error {
return nil
}
func decodeRemoveClient(event map[string]interface{}) removeEvent {
func decodeRemoveClient(event map[string]any) removeEvent {
return removeEvent{
id: events.Read(event, "id", ""),
}
}
func decodeUpdateChannel(event map[string]interface{}) updateChannelEvent {
metadata := events.Read(event, "metadata", map[string]interface{}{})
func decodeUpdateChannel(event map[string]any) updateChannelEvent {
metadata := events.Read(event, "metadata", map[string]any{})
return updateChannelEvent{
id: events.Read(event, "id", ""),
@@ -107,13 +107,13 @@ func decodeUpdateChannel(event map[string]interface{}) updateChannelEvent {
}
}
func decodeRemoveChannel(event map[string]interface{}) removeEvent {
func decodeRemoveChannel(event map[string]any) removeEvent {
return removeEvent{
id: events.Read(event, "id", ""),
}
}
func decodeConnectClient(event map[string]interface{}) connectionEvent {
func decodeConnectClient(event map[string]any) connectionEvent {
if events.Read(event, "memberKind", "") != memberKind && events.Read(event, "relation", "") != relation {
return connectionEvent{}
}
@@ -124,7 +124,7 @@ func decodeConnectClient(event map[string]interface{}) connectionEvent {
}
}
func decodeDisconnectClient(event map[string]interface{}) connectionEvent {
func decodeDisconnectClient(event map[string]any) connectionEvent {
if events.Read(event, "memberKind", "") != memberKind && events.Read(event, "relation", "") != relation {
return connectionEvent{}
}
+22 -22
View File
@@ -47,8 +47,8 @@ type configEvent struct {
operation string
}
func (ce configEvent) Encode() (map[string]interface{}, error) {
val := map[string]interface{}{
func (ce configEvent) Encode() (map[string]any, error) {
val := map[string]any{
"state": ce.State.String(),
"operation": ce.operation,
}
@@ -94,8 +94,8 @@ type removeConfigEvent struct {
client string
}
func (rce removeConfigEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
func (rce removeConfigEvent) Encode() (map[string]any, error) {
return map[string]any{
"client_id": rce.client,
"operation": configRemove,
}, nil
@@ -108,8 +108,8 @@ type listConfigsEvent struct {
partialMatch map[string]string
}
func (rce listConfigsEvent) Encode() (map[string]interface{}, error) {
val := map[string]interface{}{
func (rce listConfigsEvent) Encode() (map[string]any, error) {
val := map[string]any{
"offset": rce.offset,
"limit": rce.limit,
"operation": configList,
@@ -130,8 +130,8 @@ type bootstrapEvent struct {
success bool
}
func (be bootstrapEvent) Encode() (map[string]interface{}, error) {
val := map[string]interface{}{
func (be bootstrapEvent) Encode() (map[string]any, error) {
val := map[string]any{
"external_id": be.externalID,
"success": be.success,
"operation": clientBootstrap,
@@ -179,8 +179,8 @@ type changeStateEvent struct {
state bootstrap.State
}
func (cse changeStateEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
func (cse changeStateEvent) Encode() (map[string]any, error) {
return map[string]any{
"client_id": cse.mgClient,
"state": cse.state.String(),
"operation": clientStateChange,
@@ -192,8 +192,8 @@ type updateConnectionsEvent struct {
mgChannels []string
}
func (uce updateConnectionsEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
func (uce updateConnectionsEvent) Encode() (map[string]any, error) {
return map[string]any{
"client_id": uce.mgClient,
"channels": uce.mgChannels,
"operation": clientUpdateConnections,
@@ -207,8 +207,8 @@ type updateCertEvent struct {
caCert string
}
func (uce updateCertEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
func (uce updateCertEvent) Encode() (map[string]any, error) {
return map[string]any{
"client_id": uce.clientID,
"client_cert": uce.clientCert,
"client_key": uce.clientKey,
@@ -222,8 +222,8 @@ type removeHandlerEvent struct {
operation string
}
func (rhe removeHandlerEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
func (rhe removeHandlerEvent) Encode() (map[string]any, error) {
return map[string]any{
"config_id": rhe.id,
"operation": rhe.operation,
}, nil
@@ -233,8 +233,8 @@ type updateChannelHandlerEvent struct {
bootstrap.Channel
}
func (uche updateChannelHandlerEvent) Encode() (map[string]interface{}, error) {
val := map[string]interface{}{
func (uche updateChannelHandlerEvent) Encode() (map[string]any, error) {
val := map[string]any{
"operation": channelUpdateHandler,
}
@@ -255,8 +255,8 @@ type connectClientEvent struct {
channelID string
}
func (cte connectClientEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
func (cte connectClientEvent) Encode() (map[string]any, error) {
return map[string]any{
"client_id": cte.clientID,
"channel_id": cte.channelID,
"operation": clientConnect,
@@ -268,8 +268,8 @@ type disconnectClientEvent struct {
channelID string
}
func (dte disconnectClientEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
func (dte disconnectClientEvent) Encode() (map[string]any, error) {
return map[string]any{
"client_id": dte.clientID,
"channel_id": dte.channelID,
"operation": clientDisconnect,
+52 -52
View File
@@ -72,7 +72,7 @@ var (
channel = bootstrap.Channel{
ID: testsutil.GenerateUUID(&testing.T{}),
Name: "name",
Metadata: map[string]interface{}{"name": "value"},
Metadata: map[string]any{"name": "value"},
}
config = bootstrap.Config{
@@ -136,7 +136,7 @@ func TestAdd(t *testing.T) {
listErr error
saveErr error
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "create config successfully",
@@ -145,7 +145,7 @@ func TestAdd(t *testing.T) {
id: validID,
domainID: domainID,
channel: config.Channels,
event: map[string]interface{}{
event: map[string]any{
"client_id": "1",
"domain_id": domainID,
"name": config.Name,
@@ -205,7 +205,7 @@ func TestAdd(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
event := streams[0].Messages
lastID = event[0].ID
@@ -237,7 +237,7 @@ func TestView(t *testing.T) {
domainID string
retrieveErr error
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "view successfully",
@@ -246,7 +246,7 @@ func TestView(t *testing.T) {
id: validID,
domainID: domainID,
err: nil,
event: map[string]interface{}{
event: map[string]any{
"client_id": config.ClientID,
"domain_id": config.DomainID,
"name": config.Name,
@@ -282,7 +282,7 @@ func TestView(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
msg := streams[0].Messages[0]
event = msg.Values
@@ -329,7 +329,7 @@ func TestUpdate(t *testing.T) {
domainID string
updateErr error
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "update config successfully",
@@ -338,7 +338,7 @@ func TestUpdate(t *testing.T) {
id: validID,
domainID: domainID,
err: nil,
event: map[string]interface{}{
event: map[string]any{
"name": modified.Name,
"content": modified.Content,
"timestamp": time.Now().UnixNano(),
@@ -376,7 +376,7 @@ func TestUpdate(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
msg := streams[0].Messages[0]
event = msg.Values
@@ -409,7 +409,7 @@ func TestUpdateConnections(t *testing.T) {
listErr error
updateErr error
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "update connections successfully",
@@ -419,7 +419,7 @@ func TestUpdateConnections(t *testing.T) {
domainID: domainID,
connections: []string{config.Channels[0].ID},
err: nil,
event: map[string]interface{}{
event: map[string]any{
"client_id": config.ClientID,
"channels": "2",
"timestamp": time.Now().Unix(),
@@ -488,7 +488,7 @@ func TestUpdateConnections(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
event := streams[0].Messages
lastID = event[0].ID
@@ -520,7 +520,7 @@ func TestUpdateCert(t *testing.T) {
caCert string
updateErr error
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "update cert successfully",
@@ -532,7 +532,7 @@ func TestUpdateCert(t *testing.T) {
clientKey: "clientKey",
caCert: "caCert",
err: nil,
event: map[string]interface{}{
event: map[string]any{
"client_secret": config.ClientSecret,
"client_cert": "clientCert",
"client_key": "clientKey",
@@ -599,7 +599,7 @@ func TestUpdateCert(t *testing.T) {
clientKey: "clientKey",
caCert: "",
err: nil,
event: map[string]interface{}{
event: map[string]any{
"client_secret": config.ClientSecret,
"client_cert": "clientCert",
"client_key": "clientKey",
@@ -624,7 +624,7 @@ func TestUpdateCert(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
event := streams[0].Messages
lastID = event[0].ID
@@ -667,7 +667,7 @@ func TestList(t *testing.T) {
listObjectsErr error
retrieveErr error
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "list successfully as super admin",
@@ -686,7 +686,7 @@ func TestList(t *testing.T) {
limit: 10,
listObjectsResponse: policysvc.PolicyPage{},
err: nil,
event: map[string]interface{}{
event: map[string]any{
"client_id": c.ClientID,
"domain_id": c.DomainID,
"name": c.Name,
@@ -714,7 +714,7 @@ func TestList(t *testing.T) {
limit: 10,
listObjectsResponse: policysvc.PolicyPage{},
err: nil,
event: map[string]interface{}{
event: map[string]any{
"client_id": c.ClientID,
"domain_id": c.DomainID,
"name": c.Name,
@@ -742,7 +742,7 @@ func TestList(t *testing.T) {
limit: 10,
listObjectsResponse: policysvc.PolicyPage{},
err: nil,
event: map[string]interface{}{
event: map[string]any{
"client_id": c.ClientID,
"domain_id": c.DomainID,
"name": c.Name,
@@ -831,7 +831,7 @@ func TestList(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
event := streams[0].Messages
lastID = event[0].ID
@@ -862,7 +862,7 @@ func TestRemove(t *testing.T) {
session smqauthn.Session
removeErr error
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "remove config successfully",
@@ -871,7 +871,7 @@ func TestRemove(t *testing.T) {
userID: validID,
domainID: domainID,
err: nil,
event: map[string]interface{}{
event: map[string]any{
"client_id": config.ClientID,
"timestamp": time.Now().Unix(),
"operation": configRemove,
@@ -902,7 +902,7 @@ func TestRemove(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
event := streams[0].Messages
lastID = event[0].ID
@@ -925,14 +925,14 @@ func TestBootstrap(t *testing.T) {
externalKey string
err error
retrieveErr error
event map[string]interface{}
event map[string]any
}{
{
desc: "bootstrap successfully",
externalID: config.ExternalID,
externalKey: config.ExternalKey,
err: nil,
event: map[string]interface{}{
event: map[string]any{
"external_id": config.ExternalID,
"success": "1",
"timestamp": time.Now().Unix(),
@@ -945,7 +945,7 @@ func TestBootstrap(t *testing.T) {
externalKey: "external_id",
retrieveErr: bootstrap.ErrBootstrap,
err: bootstrap.ErrBootstrap,
event: map[string]interface{}{
event: map[string]any{
"external_id": "external_id",
"success": "0",
"timestamp": time.Now().Unix(),
@@ -966,7 +966,7 @@ func TestBootstrap(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
event := streams[0].Messages
lastID = event[0].ID
@@ -997,7 +997,7 @@ func TestChangeState(t *testing.T) {
stateErr error
authenticateErr error
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "change state to active",
@@ -1008,7 +1008,7 @@ func TestChangeState(t *testing.T) {
state: bootstrap.Active,
authResponse: authn.Session{},
err: nil,
event: map[string]interface{}{
event: map[string]any{
"client_id": config.ClientID,
"state": bootstrap.Active.String(),
"timestamp": time.Now().Unix(),
@@ -1065,7 +1065,7 @@ func TestChangeState(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
event := streams[0].Messages
lastID = event[0].ID
@@ -1088,13 +1088,13 @@ func TestUpdateChannelHandler(t *testing.T) {
desc string
channel bootstrap.Channel
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "update channel handler successfully",
channel: channel,
err: nil,
event: map[string]interface{}{
event: map[string]any{
"channel_id": channel.ID,
"metadata": "{\"name\":\"value\"}",
"name": channel.Name,
@@ -1125,7 +1125,7 @@ func TestUpdateChannelHandler(t *testing.T) {
desc: "update channel handler successfully with modified fields",
channel: channel,
err: nil,
event: map[string]interface{}{
event: map[string]any{
"channel_id": channel.ID,
"metadata": "{\"name\":\"value\"}",
"name": channel.Name,
@@ -1148,7 +1148,7 @@ func TestUpdateChannelHandler(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
msg := streams[0].Messages[0]
event = msg.Values
@@ -1170,13 +1170,13 @@ func TestRemoveChannelHandler(t *testing.T) {
desc string
channelID string
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "remove channel handler successfully",
channelID: channel.ID,
err: nil,
event: map[string]interface{}{
event: map[string]any{
"config_id": channel.ID,
"operation": channelHandlerRemove,
"timestamp": time.Now().UnixNano(),
@@ -1209,7 +1209,7 @@ func TestRemoveChannelHandler(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
msg := streams[0].Messages[0]
event = msg.Values
@@ -1232,13 +1232,13 @@ func TestRemoveConfigHandler(t *testing.T) {
desc string
configID string
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "remove config handler successfully",
configID: channel.ID,
err: nil,
event: map[string]interface{}{
event: map[string]any{
"config_id": channel.ID,
"operation": configHandlerRemove,
"timestamp": time.Now().UnixNano(),
@@ -1271,7 +1271,7 @@ func TestRemoveConfigHandler(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
msg := streams[0].Messages[0]
event = msg.Values
@@ -1295,14 +1295,14 @@ func TestConnectClientHandler(t *testing.T) {
channelID string
clientID string
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "connect client handler successfully",
channelID: channel.ID,
clientID: "1",
err: nil,
event: map[string]interface{}{
event: map[string]any{
"channel_id": channel.ID,
"client_id": "1",
"operation": clientConnect,
@@ -1345,7 +1345,7 @@ func TestConnectClientHandler(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
msg := streams[0].Messages[0]
event = msg.Values
@@ -1369,14 +1369,14 @@ func TestDisconnectClientHandler(t *testing.T) {
channelID string
clientID string
err error
event map[string]interface{}
event map[string]any
}{
{
desc: "disconnect client handler successfully",
channelID: channel.ID,
clientID: "1",
err: nil,
event: map[string]interface{}{
event: map[string]any{
"channel_id": channel.ID,
"client_id": "1",
"operation": clientDisconnect,
@@ -1407,7 +1407,7 @@ func TestDisconnectClientHandler(t *testing.T) {
channelID: channel.ID,
clientID: "1",
err: nil,
event: map[string]interface{}{
event: map[string]any{
"channel_id": channel.ID,
"client_id": "1",
"operation": clientDisconnect,
@@ -1429,7 +1429,7 @@ func TestDisconnectClientHandler(t *testing.T) {
Block: time.Second,
}).Val()
var event map[string]interface{}
var event map[string]any
if len(streams) > 0 && len(streams[0].Messages) > 0 {
msg := streams[0].Messages[0]
event = msg.Values
@@ -1442,7 +1442,7 @@ func TestDisconnectClientHandler(t *testing.T) {
}
}
func test(t *testing.T, expected, actual map[string]interface{}, description string) {
func test(t *testing.T, expected, actual map[string]any, description string) {
if expected != nil && actual != nil {
ts1 := expected["timestamp"].(int64)
ats := actual["timestamp"].(string)
@@ -1466,8 +1466,8 @@ func test(t *testing.T, expected, actual map[string]interface{}, description str
delete(actual, "occurred_at")
}
exchs := expected["channels"].([]interface{})
achs := actual["channels"].([]interface{})
exchs := expected["channels"].([]any)
achs := actual["channels"].([]any)
if exchs != nil && achs != nil {
if assert.Len(t, exchs, len(achs), fmt.Sprintf("%s: got incorrect number of channels\n", description)) {
+8 -8
View File
@@ -40,23 +40,23 @@ func (_m *ConfigReader) EXPECT() *ConfigReader_Expecter {
}
// ReadConfig provides a mock function for the type ConfigReader
func (_mock *ConfigReader) ReadConfig(config bootstrap.Config, b bool) (interface{}, error) {
func (_mock *ConfigReader) ReadConfig(config bootstrap.Config, b bool) (any, error) {
ret := _mock.Called(config, b)
if len(ret) == 0 {
panic("no return value specified for ReadConfig")
}
var r0 interface{}
var r0 any
var r1 error
if returnFunc, ok := ret.Get(0).(func(bootstrap.Config, bool) (interface{}, error)); ok {
if returnFunc, ok := ret.Get(0).(func(bootstrap.Config, bool) (any, error)); ok {
return returnFunc(config, b)
}
if returnFunc, ok := ret.Get(0).(func(bootstrap.Config, bool) interface{}); ok {
if returnFunc, ok := ret.Get(0).(func(bootstrap.Config, bool) any); ok {
r0 = returnFunc(config, b)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(interface{})
r0 = ret.Get(0).(any)
}
}
if returnFunc, ok := ret.Get(1).(func(bootstrap.Config, bool) error); ok {
@@ -97,12 +97,12 @@ func (_c *ConfigReader_ReadConfig_Call) Run(run func(config bootstrap.Config, b
return _c
}
func (_c *ConfigReader_ReadConfig_Call) Return(ifaceVal interface{}, err error) *ConfigReader_ReadConfig_Call {
_c.Call.Return(ifaceVal, err)
func (_c *ConfigReader_ReadConfig_Call) Return(v any, err error) *ConfigReader_ReadConfig_Call {
_c.Call.Return(v, err)
return _c
}
func (_c *ConfigReader_ReadConfig_Call) RunAndReturn(run func(config bootstrap.Config, b bool) (interface{}, error)) *ConfigReader_ReadConfig_Call {
func (_c *ConfigReader_ReadConfig_Call) RunAndReturn(run func(config bootstrap.Config, b bool) (any, error)) *ConfigReader_ReadConfig_Call {
_c.Call.Return(run)
return _c
}
+2 -2
View File
@@ -478,8 +478,8 @@ func (cr configRepository) DisconnectClient(ctx context.Context, channelID, clie
return nil
}
func buildRetrieveQueryParams(domainID string, clientIDs []string, filter bootstrap.Filter) (string, []interface{}) {
params := []interface{}{}
func buildRetrieveQueryParams(domainID string, clientIDs []string, filter bootstrap.Filter) (string, []any) {
params := []any{}
queries := []string{}
if len(clientIDs) != 0 {
+3 -3
View File
@@ -29,8 +29,8 @@ var (
ExternalKey: "external-key",
DomainID: testsutil.GenerateUUID(&testing.T{}),
Channels: []bootstrap.Channel{
{ID: "1", Name: "name 1", Metadata: map[string]interface{}{"meta": 1.0}},
{ID: "2", Name: "name 2", Metadata: map[string]interface{}{"meta": 2.0}},
{ID: "1", Name: "name 1", Metadata: map[string]any{"meta": 1.0}},
{ID: "2", Name: "name 2", Metadata: map[string]any{"meta": 2.0}},
},
Content: "content",
State: bootstrap.Inactive,
@@ -669,7 +669,7 @@ func TestUpdateChannel(t *testing.T) {
update := bootstrap.Channel{
ID: id,
Name: "update name",
Metadata: map[string]interface{}{"update": "metadata update"},
Metadata: map[string]any{"update": "metadata update"},
}
err = repo.UpdateChannel(context.Background(), update)
assert.Nil(t, err, fmt.Sprintf("updating config expected to succeed: %s.\n", err))
+2 -2
View File
@@ -28,7 +28,7 @@ type bootstrapRes struct {
type channelRes struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
Metadata any `json:"metadata,omitempty"`
}
func (res bootstrapRes) Code() int {
@@ -53,7 +53,7 @@ func NewConfigReader(encKey []byte) ConfigReader {
return reader{encKey: encKey}
}
func (r reader) ReadConfig(cfg Config, secure bool) (interface{}, error) {
func (r reader) ReadConfig(cfg Config, secure bool) (any, error) {
var channels []channelRes
for _, ch := range cfg.Channels {
channels = append(channels, channelRes{ID: ch.ID, Name: ch.Name, Metadata: ch.Metadata})
+3 -3
View File
@@ -20,7 +20,7 @@ import (
type readChan struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
Metadata any `json:"metadata,omitempty"`
}
type readResp struct {
@@ -59,7 +59,7 @@ func TestReadConfig(t *testing.T) {
{
ID: "smq_id",
Name: "smq_name",
Metadata: map[string]interface{}{"key": "value}"},
Metadata: map[string]any{"key": "value}"},
},
},
Content: "content",
@@ -71,7 +71,7 @@ func TestReadConfig(t *testing.T) {
{
ID: "smq_id",
Name: "smq_name",
Metadata: map[string]interface{}{"key": "value}"},
Metadata: map[string]any{"key": "value}"},
},
},
Content: "content",
+1 -1
View File
@@ -114,7 +114,7 @@ type Service interface {
// is to provide convenient way to generate custom configuration response
// based on the specific Config which will be consumed by the client.
type ConfigReader interface {
ReadConfig(Config, bool) (interface{}, error)
ReadConfig(Config, bool) (any, error)
}
type bootstrapService struct {
+2 -2
View File
@@ -46,7 +46,7 @@ var (
channel = bootstrap.Channel{
ID: testsutil.GenerateUUID(&testing.T{}),
Name: "name",
Metadata: map[string]interface{}{"name": "value"},
Metadata: map[string]any{"name": "value"},
}
config = bootstrap.Config{
@@ -956,7 +956,7 @@ func TestUpdateChannelHandler(t *testing.T) {
ch := bootstrap.Channel{
ID: channel.ID,
Name: "new name",
Metadata: map[string]interface{}{"meta": "new"},
Metadata: map[string]any{"meta": "new"},
}
cases := []struct {
+1 -1
View File
@@ -256,7 +256,7 @@ func setConfigValue(key, value string) error {
}
}
configKeyToField := map[string]interface{}{
configKeyToField := map[string]any{
"channels_url": &config.Remotes.ChannelsURL,
"clients_url": &config.Remotes.ClientsURL,
"groups_url": &config.Remotes.GroupsURL,
+1 -1
View File
@@ -43,7 +43,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 {
+5 -5
View File
@@ -129,7 +129,7 @@ func loadConfig() (provision.Config, error) {
return provision.Config{}, errors.New("Can't auto whitelist if auto config save is off")
}
var content map[string]interface{}
var content map[string]any
if cfg.BSContent != "" {
if err := json.Unmarshal([]byte(cfg.BSContent), &content); err != nil {
return provision.Config{}, errFailedToReadBootstrapContent
@@ -141,23 +141,23 @@ func loadConfig() (provision.Config, error) {
cfg.Channels = []channels.Channel{
{
Name: "control-channel",
Metadata: map[string]interface{}{"type": "control"},
Metadata: map[string]any{"type": "control"},
}, {
Name: "data-channel",
Metadata: map[string]interface{}{"type": "data"},
Metadata: map[string]any{"type": "data"},
},
}
cfg.Clients = []clients.Client{
{
Name: "client",
Metadata: map[string]interface{}{"external_id": "xxxxxx"},
Metadata: map[string]any{"external_id": "xxxxxx"},
},
}
return cfg, nil
}
func mergeConfigs(dst, src interface{}) interface{} {
func mergeConfigs(dst, src any) any {
d := reflect.ValueOf(dst).Elem()
s := reflect.ValueOf(src).Elem()
+4 -4
View File
@@ -13,7 +13,7 @@ import (
)
func createSubscriptionEndpoint(svc notifiers.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(createSubReq)
if err := req.validate(); err != nil {
return createSubRes{}, errors.Wrap(apiutil.ErrValidation, err)
@@ -35,7 +35,7 @@ func createSubscriptionEndpoint(svc notifiers.Service) endpoint.Endpoint {
}
func viewSubscriptionEndpoint(svc notifiers.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(subReq)
if err := req.validate(); err != nil {
return viewSubRes{}, errors.Wrap(apiutil.ErrValidation, err)
@@ -55,7 +55,7 @@ func viewSubscriptionEndpoint(svc notifiers.Service) endpoint.Endpoint {
}
func listSubscriptionsEndpoint(svc notifiers.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(listSubsReq)
if err := req.validate(); err != nil {
return listSubsRes{}, errors.Wrap(apiutil.ErrValidation, err)
@@ -90,7 +90,7 @@ func listSubscriptionsEndpoint(svc notifiers.Service) endpoint.Endpoint {
}
func deleteSubscriptionEndpoint(svc notifiers.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(subReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
+1 -1
View File
@@ -74,7 +74,7 @@ func newServer() (*httptest.Server, *mocks.Service) {
return httptest.NewServer(mux), svc
}
func toJSON(data interface{}) string {
func toJSON(data any) string {
jsonData, err := json.Marshal(data)
if err != nil {
return ""
+1 -1
View File
@@ -114,7 +114,7 @@ func (lm *loggingMiddleware) RemoveSubscription(ctx context.Context, token, id s
// ConsumeBlocking logs the consume_blocking request. It logs the time it took to complete the request.
// If the request fails, it logs the error.
func (lm *loggingMiddleware) ConsumeBlocking(ctx context.Context, msg interface{}) (err error) {
func (lm *loggingMiddleware) ConsumeBlocking(ctx context.Context, msg any) (err error) {
defer func(begin time.Time) {
args := []any{
slog.String("duration", time.Since(begin).String()),
+1 -1
View File
@@ -71,7 +71,7 @@ func (ms *metricsMiddleware) RemoveSubscription(ctx context.Context, token, id s
}
// ConsumeBlocking instruments ConsumeBlocking method with metrics.
func (ms *metricsMiddleware) ConsumeBlocking(ctx context.Context, msg interface{}) error {
func (ms *metricsMiddleware) ConsumeBlocking(ctx context.Context, msg any) error {
defer func(begin time.Time) {
ms.counter.With("method", "consume").Add(1)
ms.latency.With("method", "consume").Observe(time.Since(begin).Seconds())
+3 -3
View File
@@ -81,7 +81,7 @@ func MakeHandler(svc notifiers.Service, logger *slog.Logger, instanceID string)
return mux
}
func decodeCreate(_ context.Context, r *http.Request) (interface{}, error) {
func decodeCreate(_ context.Context, r *http.Request) (any, error) {
if !strings.Contains(r.Header.Get("Content-Type"), contentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}
@@ -94,7 +94,7 @@ func decodeCreate(_ context.Context, r *http.Request) (interface{}, error) {
return req, nil
}
func decodeSubscription(_ context.Context, r *http.Request) (interface{}, error) {
func decodeSubscription(_ context.Context, r *http.Request) (any, error) {
req := subReq{
id: chi.URLParam(r, "subID"),
token: apiutil.ExtractBearerToken(r),
@@ -103,7 +103,7 @@ func decodeSubscription(_ context.Context, r *http.Request) (interface{}, error)
return req, nil
}
func decodeList(_ context.Context, r *http.Request) (interface{}, error) {
func decodeList(_ context.Context, r *http.Request) (any, error) {
req := listSubsReq{token: apiutil.ExtractBearerToken(r)}
vals := r.URL.Query()[topicKey]
if len(vals) > 0 {
+8 -8
View File
@@ -22,10 +22,10 @@ type database struct {
// Database provides a database interface.
type Database interface {
NamedExecContext(context.Context, string, interface{}) (sql.Result, error)
QueryRowxContext(context.Context, string, ...interface{}) *sqlx.Row
NamedQueryContext(context.Context, string, interface{}) (*sqlx.Rows, error)
GetContext(context.Context, interface{}, string, ...interface{}) error
NamedExecContext(context.Context, string, any) (sql.Result, error)
QueryRowxContext(context.Context, string, ...any) *sqlx.Row
NamedQueryContext(context.Context, string, any) (*sqlx.Rows, error)
GetContext(context.Context, any, string, ...any) error
}
// NewDatabase creates a SubscriptionsDatabase instance.
@@ -36,25 +36,25 @@ func NewDatabase(db *sqlx.DB, tracer trace.Tracer) Database {
}
}
func (dm database) NamedExecContext(ctx context.Context, query string, args interface{}) (sql.Result, error) {
func (dm database) NamedExecContext(ctx context.Context, query string, args any) (sql.Result, error) {
ctx, span := dm.addSpanTags(ctx, "NamedExecContext", query)
defer span.End()
return dm.db.NamedExecContext(ctx, query, args)
}
func (dm database) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row {
func (dm database) QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row {
ctx, span := dm.addSpanTags(ctx, "QueryRowxContext", query)
defer span.End()
return dm.db.QueryRowxContext(ctx, query, args...)
}
func (dm database) NamedQueryContext(ctx context.Context, query string, args interface{}) (*sqlx.Rows, error) {
func (dm database) NamedQueryContext(ctx context.Context, query string, args any) (*sqlx.Rows, error) {
ctx, span := dm.addSpanTags(ctx, "NamedQueryContext", query)
defer span.End()
return dm.db.NamedQueryContext(ctx, query, args)
}
func (dm database) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
func (dm database) GetContext(ctx context.Context, dest any, query string, args ...any) error {
ctx, span := dm.addSpanTags(ctx, "GetContext", query)
defer span.End()
return dm.db.GetContext(ctx, dest, query, args...)
@@ -66,7 +66,7 @@ func (repo subscriptionsRepo) Retrieve(ctx context.Context, id string) (notifier
func (repo subscriptionsRepo) RetrieveAll(ctx context.Context, pm notifiers.PageMetadata) (notifiers.Page, error) {
q := `SELECT id, owner_id, contact, topic FROM subscriptions`
args := make(map[string]interface{})
args := make(map[string]any)
if pm.Topic != "" {
args["topic"] = pm.Topic
}
@@ -132,7 +132,7 @@ func (repo subscriptionsRepo) Remove(ctx context.Context, id string) error {
return nil
}
func total(ctx context.Context, db Database, query string, params interface{}) (uint, error) {
func total(ctx context.Context, db Database, query string, params any) (uint, error) {
rows, err := db.NamedQueryContext(ctx, query, params)
if err != nil {
return 0, err
+2 -2
View File
@@ -103,7 +103,7 @@ func (ns *notifierService) RemoveSubscription(ctx context.Context, token, id str
return ns.subs.Remove(ctx, id)
}
func (ns *notifierService) ConsumeBlocking(ctx context.Context, message interface{}) error {
func (ns *notifierService) ConsumeBlocking(ctx context.Context, message any) error {
msg, ok := message.(*messaging.Message)
if !ok {
return ErrMessage
@@ -136,7 +136,7 @@ func (ns *notifierService) ConsumeBlocking(ctx context.Context, message interfac
return nil
}
func (ns *notifierService) ConsumeAsync(ctx context.Context, message interface{}) {
func (ns *notifierService) ConsumeAsync(ctx context.Context, message any) {
msg, ok := message.(*messaging.Message)
if !ok {
ns.errCh <- ErrMessage
+2 -2
View File
@@ -66,7 +66,7 @@ func NewBlocking(tracer trace.Tracer, consumerBlock consumers.BlockingConsumer,
}
// ConsumeBlocking traces consume operations for message/s consumed.
func (tm *tracingMiddlewareBlock) ConsumeBlocking(ctx context.Context, messages interface{}) error {
func (tm *tracingMiddlewareBlock) ConsumeBlocking(ctx context.Context, messages any) error {
var span trace.Span
switch m := messages.(type) {
case smqjson.Messages:
@@ -86,7 +86,7 @@ func (tm *tracingMiddlewareBlock) ConsumeBlocking(ctx context.Context, messages
}
// ConsumeAsync traces consume operations for message/s consumed.
func (tm *tracingMiddlewareAsync) ConsumeAsync(ctx context.Context, messages interface{}) {
func (tm *tracingMiddlewareAsync) ConsumeAsync(ctx context.Context, messages any) {
var span trace.Span
switch m := messages.(type) {
case smqjson.Messages:
+1 -1
View File
@@ -30,7 +30,7 @@ func LoggingMiddleware(consumer consumers.BlockingConsumer, logger *slog.Logger)
// ConsumeBlocking logs the consume request. It logs the time it took to complete the request.
// If the request fails, it logs the error.
func (lm *loggingMiddleware) ConsumeBlocking(ctx context.Context, msgs interface{}) (err error) {
func (lm *loggingMiddleware) ConsumeBlocking(ctx context.Context, msgs any) (err error) {
defer func(begin time.Time) {
args := []any{
slog.String("duration", time.Since(begin).String()),
+1 -1
View File
@@ -32,7 +32,7 @@ func MetricsMiddleware(consumer consumers.BlockingConsumer, counter metrics.Coun
}
// ConsumeBlocking instruments ConsumeBlocking method with metrics.
func (mm *metricsMiddleware) ConsumeBlocking(ctx context.Context, msgs interface{}) error {
func (mm *metricsMiddleware) ConsumeBlocking(ctx context.Context, msgs any) error {
defer func(begin time.Time) {
mm.counter.With("method", "consume").Add(1)
mm.latency.With("method", "consume").Observe(time.Since(begin).Seconds())
+2 -2
View File
@@ -36,7 +36,7 @@ func New(db *sqlx.DB) consumers.BlockingConsumer {
return &postgresRepo{db: db}
}
func (pr postgresRepo) ConsumeBlocking(ctx context.Context, message interface{}) (err error) {
func (pr postgresRepo) ConsumeBlocking(ctx context.Context, message any) (err error) {
switch m := message.(type) {
case smqjson.Messages:
return pr.saveJSON(ctx, m)
@@ -45,7 +45,7 @@ func (pr postgresRepo) ConsumeBlocking(ctx context.Context, message interface{})
}
}
func (pr postgresRepo) saveSenml(ctx context.Context, messages interface{}) (err error) {
func (pr postgresRepo) saveSenml(ctx context.Context, messages any) (err error) {
msgs, ok := messages.([]senml.Message)
if !ok {
return errSaveMessage
+2 -2
View File
@@ -85,12 +85,12 @@ func TestSaveJSON(t *testing.T) {
Created: time.Now().Unix(),
Subtopic: "subtopic/format/some_json",
Protocol: "mqtt",
Payload: map[string]interface{}{
Payload: map[string]any{
"field_1": 123,
"field_2": "value",
"field_3": false,
"field_4": 12.344,
"field_5": map[string]interface{}{
"field_5": map[string]any{
"field_1": "value",
"field_2": 42,
},
+2 -2
View File
@@ -38,7 +38,7 @@ func New(db *sqlx.DB) consumers.BlockingConsumer {
return &timescaleRepo{db: db}
}
func (tr *timescaleRepo) ConsumeBlocking(ctx context.Context, message interface{}) (err error) {
func (tr *timescaleRepo) ConsumeBlocking(ctx context.Context, message any) (err error) {
switch m := message.(type) {
case smqjson.Messages:
return tr.saveJSON(ctx, m)
@@ -51,7 +51,7 @@ func (tr *timescaleRepo) ConsumeBlocking(ctx context.Context, message interface{
}
}
func (tr timescaleRepo) saveSenml(ctx context.Context, messages interface{}) (err error) {
func (tr timescaleRepo) saveSenml(ctx context.Context, messages any) (err error) {
msgs, ok := messages.([]senml.Message)
if !ok {
return errSaveMessage
+2 -2
View File
@@ -85,12 +85,12 @@ func TestSaveJSON(t *testing.T) {
Created: time.Now().Unix(),
Subtopic: "subtopic/format/some_json",
Protocol: "mqtt",
Payload: map[string]interface{}{
Payload: map[string]any{
"field_1": 123,
"field_2": "value",
"field_3": false,
"field_4": 12.344,
"field_5": map[string]interface{}{
"field_5": map[string]any{
"field_1": "value",
"field_2": 42,
},
+1 -1
View File
@@ -35,7 +35,7 @@ const (
// MGKey is key of corresponding SuperMQ Client.
// MGChannels is a list of SuperMQ Channels corresponding SuperMQ Client connects to.
type BootstrapConfig struct {
Channels interface{} `json:"channels,omitempty"`
Channels any `json:"channels,omitempty"`
ExternalID string `json:"external_id,omitempty"`
ExternalKey string `json:"external_key,omitempty"`
ClientID string `json:"client_id,omitempty"`
+7 -7
View File
@@ -130,7 +130,7 @@ var (
type readerChannelRes struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
Metadata any `json:"metadata,omitempty"`
}
func setupBootstrap() (*httptest.Server, *bmocks.Service, *bmocks.ConfigReader, *authnmocks.Authentication) {
@@ -196,7 +196,7 @@ func TestAddBootstrap(t *testing.T) {
domainID: domainID,
token: validToken,
cfg: sdk.BootstrapConfig{
Channels: map[string]interface{}{
Channels: map[string]any{
"channel1": make(chan int),
},
ExternalID: externalId,
@@ -294,7 +294,7 @@ func TestListBootstraps(t *testing.T) {
unmarshalableConfig.Channels = []bootstrap.Channel{
{
ID: channel1Id,
Metadata: map[string]interface{}{
Metadata: map[string]any{
"test": make(chan int),
},
},
@@ -366,7 +366,7 @@ func TestListBootstraps(t *testing.T) {
pageMeta: sdk.PageMetadata{
Offset: 1,
Limit: 10,
Metadata: map[string]interface{}{
Metadata: map[string]any{
"test": make(chan int),
},
},
@@ -598,7 +598,7 @@ func TestViewBootstrap(t *testing.T) {
Channels: []bootstrap.Channel{
{
ID: channel1Id,
Metadata: map[string]interface{}{
Metadata: map[string]any{
"test": make(chan int),
},
},
@@ -699,7 +699,7 @@ func TestUpdateBootstrap(t *testing.T) {
domainID: domainID,
token: validToken,
cfg: sdk.BootstrapConfig{
Channels: map[string]interface{}{
Channels: map[string]any{
"channel1": make(chan int),
},
ExternalID: externalId,
@@ -1131,7 +1131,7 @@ func TestBoostrap(t *testing.T) {
externalKey string
svcResp bootstrap.Config
svcErr error
readerResp interface{}
readerResp any
readerErr error
response sdk.BootstrapConfig
err errors.SDKError
+1 -1
View File
@@ -51,7 +51,7 @@ func (sdk mgSDK) withMessageQueryParams(baseURL, endpoint string, mpm MessagePag
if err != nil {
return "", err
}
q := map[string]interface{}{}
q := map[string]any{}
if err := json.Unmarshal(b, &q); err != nil {
return "", err
}
+1 -1
View File
@@ -190,7 +190,7 @@ func TestReadMessages(t *testing.T) {
PageMetadata: sdk.PageMetadata{
Offset: 0,
Limit: 10,
Metadata: map[string]interface{}{
Metadata: map[string]any{
"key": make(chan int),
},
},
+1 -1
View File
@@ -23,7 +23,7 @@ import (
var _ SDK = (*mgSDK)(nil)
type Metadata map[string]interface{}
type Metadata map[string]any
type PageMetadata struct {
Total uint64 `json:"total"`
+2 -2
View File
@@ -13,7 +13,7 @@ import (
)
func doProvision(svc provision.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(provisionReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
@@ -38,7 +38,7 @@ func doProvision(svc provision.Service) endpoint.Endpoint {
}
func getMapping(svc provision.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(mappingReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
+1 -1
View File
@@ -206,7 +206,7 @@ func TestMapping(t *testing.T) {
for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
repocall := svc.On("Mapping", mock.Anything, tc.token).Return(map[string]interface{}{}, tc.svcErr)
repocall := svc.On("Mapping", mock.Anything, tc.token).Return(map[string]any{}, tc.svcErr)
req := testRequest{
client: is.Client(),
method: http.MethodGet,
+1 -1
View File
@@ -61,7 +61,7 @@ func (lm *loggingMiddleware) Cert(ctx context.Context, domainID, token, clientID
return lm.svc.Cert(ctx, domainID, token, clientID, duration)
}
func (lm *loggingMiddleware) Mapping(ctx context.Context, token string) (res map[string]interface{}, err error) {
func (lm *loggingMiddleware) Mapping(ctx context.Context, token string) (res map[string]any, err error) {
defer func(begin time.Time) {
args := []any{
slog.String("duration", time.Since(begin).String()),
+1 -1
View File
@@ -35,7 +35,7 @@ func (res provisionRes) Empty() bool {
}
type mappingRes struct {
Data interface{}
Data any
}
func (res mappingRes) Code() int {
+2 -2
View File
@@ -53,7 +53,7 @@ func MakeHandler(svc provision.Service, logger *slog.Logger, instanceID string)
return r
}
func decodeProvisionRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeProvisionRequest(_ context.Context, r *http.Request) (any, error) {
if r.Header.Get("Content-Type") != contentType {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}
@@ -69,7 +69,7 @@ func decodeProvisionRequest(_ context.Context, r *http.Request) (interface{}, er
return req, nil
}
func decodeMappingRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeMappingRequest(_ context.Context, r *http.Request) (any, error) {
if r.Header.Get("Content-Type") != contentType {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}
+1 -1
View File
@@ -39,7 +39,7 @@ type Bootstrap struct {
X509Provision bool `toml:"x509_provision" env:"SMQ_PROVISION_X509_PROVISIONING" envDefault:"false"`
Provision bool `toml:"provision" env:"SMQ_PROVISION_BS_CONFIG_PROVISIONING" envDefault:"true"`
AutoWhiteList bool `toml:"autowhite_list" env:"SMQ_PROVISION_BS_AUTO_WHITELIST" envDefault:"true"`
Content map[string]interface{} `toml:"content"`
Content map[string]any `toml:"content"`
}
// Gateway represetns the Gateway config.
+6 -6
View File
@@ -28,7 +28,7 @@ var (
X509Provision: true,
Provision: true,
AutoWhiteList: true,
Content: map[string]interface{}{
Content: map[string]any{
"test": "test",
},
},
@@ -37,7 +37,7 @@ var (
ID: "1234567890",
Name: "test",
Tags: []string{"test"},
Metadata: map[string]interface{}{
Metadata: map[string]any{
"test": "test",
},
Actions: []string{},
@@ -50,7 +50,7 @@ var (
ID: "1234567890",
Name: "test",
Tags: []string{"test"},
Metadata: map[string]interface{}{
Metadata: map[string]any{
"test": "test",
},
Actions: []string{},
@@ -65,7 +65,7 @@ var (
validConfigFile = "./config.toml"
invalidConfig = provision.Config{
Bootstrap: provision.Bootstrap{
Content: map[string]interface{}{
Content: map[string]any{
"invalid": make(chan int),
},
},
@@ -74,7 +74,7 @@ var (
)
func createInvalidConfigFile() error {
config := map[string]interface{}{
config := map[string]any{
"invalid": "invalid",
}
b, err := toml.Marshal(config)
@@ -166,7 +166,7 @@ func TestSave(t *testing.T) {
cfg, err := provision.Read(c.file)
if c.cfg.Bootstrap.Content == nil {
c.cfg.Bootstrap.Content = map[string]interface{}{}
c.cfg.Bootstrap.Content = map[string]any{}
}
assert.Equal(t, c.err, err)
assert.Equal(t, c.cfg, cfg)
+8 -8
View File
@@ -132,23 +132,23 @@ func (_c *Service_Cert_Call) RunAndReturn(run func(ctx context.Context, domainID
}
// Mapping provides a mock function for the type Service
func (_mock *Service) Mapping(ctx context.Context, token string) (map[string]interface{}, error) {
func (_mock *Service) Mapping(ctx context.Context, token string) (map[string]any, error) {
ret := _mock.Called(ctx, token)
if len(ret) == 0 {
panic("no return value specified for Mapping")
}
var r0 map[string]interface{}
var r0 map[string]any
var r1 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 {
return returnFunc(ctx, token)
}
if returnFunc, ok := ret.Get(0).(func(context.Context, string) map[string]interface{}); ok {
if returnFunc, ok := ret.Get(0).(func(context.Context, string) map[string]any); ok {
r0 = returnFunc(ctx, token)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(map[string]interface{})
r0 = ret.Get(0).(map[string]any)
}
}
if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok {
@@ -189,12 +189,12 @@ func (_c *Service_Mapping_Call) Run(run func(ctx context.Context, token string))
return _c
}
func (_c *Service_Mapping_Call) Return(stringToIfaceVal map[string]interface{}, err error) *Service_Mapping_Call {
_c.Call.Return(stringToIfaceVal, err)
func (_c *Service_Mapping_Call) Return(stringToV map[string]any, err error) *Service_Mapping_Call {
_c.Call.Return(stringToV, err)
return _c
}
func (_c *Service_Mapping_Call) RunAndReturn(run func(ctx context.Context, token string) (map[string]interface{}, error)) *Service_Mapping_Call {
func (_c *Service_Mapping_Call) RunAndReturn(run func(ctx context.Context, token string) (map[string]any, error)) *Service_Mapping_Call {
_c.Call.Return(run)
return _c
}
+3 -3
View File
@@ -61,7 +61,7 @@ type Service interface {
// Mapping returns current configuration used for provision
// useful for using in ui to create configuration that matches
// one created with Provision method.
Mapping(ctx context.Context, token string) (map[string]interface{}, error)
Mapping(ctx context.Context, token string) (map[string]any, error)
// Certs creates certificate for clients that communicate over mTLS
// A duration string is a possibly signed sequence of decimal numbers,
@@ -97,14 +97,14 @@ func New(cfg Config, mgsdk sdk.SDK, logger *slog.Logger) Service {
}
// Mapping retrieves current configuration.
func (ps *provisionService) Mapping(ctx context.Context, token string) (map[string]interface{}, error) {
func (ps *provisionService) Mapping(ctx context.Context, token string) (map[string]any, error) {
pm := smqSDK.PageMetadata{
Offset: uint64(offset),
Limit: uint64(limit),
}
if _, err := ps.sdk.Users(ctx, pm, token); err != nil {
return map[string]interface{}{}, errors.Wrap(ErrUnauthorized, err)
return map[string]any{}, errors.Wrap(ErrUnauthorized, err)
}
return ps.conf.Bootstrap.Content, nil
+2 -2
View File
@@ -29,7 +29,7 @@ func TestMapping(t *testing.T) {
cases := []struct {
desc string
token string
content map[string]interface{}
content map[string]any
sdkerr error
err error
}{
@@ -43,7 +43,7 @@ func TestMapping(t *testing.T) {
{
desc: "invalid token",
token: "invalid",
content: map[string]interface{}{},
content: map[string]any{},
sdkerr: errors.NewSDKErrorWithStatus(svcerr.ErrAuthentication, 401),
err: provision.ErrUnauthorized,
},
+9 -9
View File
@@ -16,7 +16,7 @@ import (
)
func addRuleEndpoint(s re.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.ErrAuthorization
@@ -35,7 +35,7 @@ func addRuleEndpoint(s re.Service) endpoint.Endpoint {
}
func viewRuleEndpoint(s re.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.ErrAuthorization
@@ -54,7 +54,7 @@ func viewRuleEndpoint(s re.Service) endpoint.Endpoint {
}
func updateRuleEndpoint(s re.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.ErrAuthorization
@@ -73,7 +73,7 @@ func updateRuleEndpoint(s re.Service) endpoint.Endpoint {
}
func updateRuleTagsEndpoint(svc re.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(updateRuleTagsReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
@@ -98,7 +98,7 @@ func updateRuleTagsEndpoint(svc re.Service) endpoint.Endpoint {
}
func updateRuleScheduleEndpoint(s re.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.ErrAuthorization
@@ -123,7 +123,7 @@ func updateRuleScheduleEndpoint(s re.Service) endpoint.Endpoint {
}
func listRulesEndpoint(s re.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.ErrAuthorization
@@ -145,7 +145,7 @@ func listRulesEndpoint(s re.Service) endpoint.Endpoint {
}
func deleteRuleEndpoint(s re.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.ErrAuthorization
@@ -164,7 +164,7 @@ func deleteRuleEndpoint(s re.Service) endpoint.Endpoint {
}
func enableRuleEndpoint(s re.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.ErrAuthorization
@@ -185,7 +185,7 @@ func enableRuleEndpoint(s re.Service) endpoint.Endpoint {
}
func disableRuleEndpoint(s re.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.ErrAuthorization
+8 -8
View File
@@ -110,7 +110,7 @@ func MakeHandler(svc re.Service, authn mgauthn.Authentication, mux *chi.Mux, log
return mux
}
func decodeAddRuleRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeAddRuleRequest(_ 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)
}
@@ -121,12 +121,12 @@ func decodeAddRuleRequest(_ context.Context, r *http.Request) (interface{}, erro
return addRuleReq{Rule: rule}, nil
}
func decodeViewRuleRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeViewRuleRequest(_ context.Context, r *http.Request) (any, error) {
id := chi.URLParam(r, ruleIdKey)
return viewRuleReq{id: id}, nil
}
func decodeUpdateRuleRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateRuleRequest(_ 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)
}
@@ -139,7 +139,7 @@ func decodeUpdateRuleRequest(_ context.Context, r *http.Request) (interface{}, e
return updateRuleReq{Rule: rule}, nil
}
func decodeUpdateRuleTags(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateRuleTags(_ 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)
}
@@ -154,7 +154,7 @@ func decodeUpdateRuleTags(_ context.Context, r *http.Request) (interface{}, erro
return req, nil
}
func decodeUpdateRuleScheduleRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateRuleScheduleRequest(_ 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)
}
@@ -169,7 +169,7 @@ func decodeUpdateRuleScheduleRequest(_ context.Context, r *http.Request) (interf
return req, nil
}
func decodeUpdateRuleStatusRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateRuleStatusRequest(_ context.Context, r *http.Request) (any, error) {
req := updateRuleStatusReq{
id: chi.URLParam(r, ruleIdKey),
}
@@ -177,7 +177,7 @@ func decodeUpdateRuleStatusRequest(_ context.Context, r *http.Request) (interfac
return req, nil
}
func decodeListRulesRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeListRulesRequest(_ 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)
@@ -229,7 +229,7 @@ func decodeListRulesRequest(_ context.Context, r *http.Request) (interface{}, er
}, nil
}
func decodeDeleteRuleRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeDeleteRuleRequest(_ context.Context, r *http.Request) (any, error) {
id := chi.URLParam(r, ruleIdKey)
return deleteRuleReq{id: id}, nil
+7 -7
View File
@@ -99,7 +99,7 @@ func prepareMsg(l *lua.LState, msg *messaging.Message) lua.LValue {
message.RawSetString("protocol", lua.LString(msg.Protocol))
message.RawSetString("created", lua.LNumber(msg.Created))
var payload interface{}
var payload any
if err := json.Unmarshal(msg.GetPayload(), &payload); err != nil {
pld := l.NewTable()
// If message is not JSON, set binary payload and exit.
@@ -116,7 +116,7 @@ func prepareMsg(l *lua.LState, msg *messaging.Message) lua.LValue {
return message
}
func traverseJson(l *lua.LState, value interface{}) lua.LValue {
func traverseJson(l *lua.LState, value any) lua.LValue {
switch val := value.(type) {
case string:
return lua.LString(val)
@@ -131,13 +131,13 @@ func traverseJson(l *lua.LState, value interface{}) lua.LValue {
return lua.LNil
case bool:
return lua.LBool(val)
case []interface{}:
case []any:
t := l.NewTable()
for i, j := range val {
t.RawSetInt(i+1, traverseJson(l, j))
}
return t
case map[string]interface{}:
case map[string]any:
t := l.NewTable()
for k, v := range val {
t.RawSetString(k, traverseJson(l, v))
@@ -148,7 +148,7 @@ func traverseJson(l *lua.LState, value interface{}) lua.LValue {
}
}
func convertLua(lv lua.LValue) interface{} {
func convertLua(lv lua.LValue) any {
switch v := lv.(type) {
case *lua.LTable:
isArray := true
@@ -159,14 +159,14 @@ func convertLua(lv lua.LValue) interface{} {
})
if isArray {
arr := []interface{}{}
arr := []any{}
v.ForEach(func(key, value lua.LValue) {
arr = append(arr, convertLua(value))
})
return arr
}
obj := map[string]interface{}{}
obj := map[string]any{}
v.ForEach(func(key, value lua.LValue) {
obj[key.String()] = convertLua(value)
})
+1 -1
View File
@@ -18,7 +18,7 @@ type Alarm struct {
RuleID string `json:"rule_id"`
}
func (a *Alarm) Run(ctx context.Context, msg *messaging.Message, val interface{}) error {
func (a *Alarm) Run(ctx context.Context, msg *messaging.Message, val any) error {
data, err := json.Marshal(val)
if err != nil {
return err
+1 -1
View File
@@ -18,7 +18,7 @@ type ChannelPublisher struct {
Topic string `json:"topic"`
}
func (p *ChannelPublisher) Run(ctx context.Context, msg *messaging.Message, val interface{}) error {
func (p *ChannelPublisher) Run(ctx context.Context, msg *messaging.Message, val any) error {
data, err := json.Marshal(val)
if err != nil {
return err
+1 -1
View File
@@ -20,7 +20,7 @@ type Email struct {
Emailer emailer.Emailer `json:"-"`
}
func (e *Email) Run(ctx context.Context, msg *messaging.Message, val interface{}) error {
func (e *Email) Run(ctx context.Context, msg *messaging.Message, val any) error {
templData := templateVal{
Message: msg,
Result: val,
+1 -1
View File
@@ -13,7 +13,7 @@ import (
type templateVal struct {
Message *messaging.Message
Result interface{}
Result any
}
// OutputType is the indicator for type of the output
+3 -3
View File
@@ -27,7 +27,7 @@ type Postgres struct {
Mapping string `json:"mapping"`
}
func (p *Postgres) Run(ctx context.Context, msg *messaging.Message, val interface{}) error {
func (p *Postgres) Run(ctx context.Context, msg *messaging.Message, val any) error {
templData := templateVal{
Message: msg,
Result: val,
@@ -44,7 +44,7 @@ func (p *Postgres) Run(ctx context.Context, msg *messaging.Message, val interfac
}
mapping := output.String()
var columns map[string]interface{}
var columns map[string]any
if err = json.Unmarshal([]byte(mapping), &columns); err != nil {
return err
}
@@ -66,7 +66,7 @@ func (p *Postgres) Run(ctx context.Context, msg *messaging.Message, val interfac
var (
cols []string
values []interface{}
values []any
placeholders []string
)
+1 -1
View File
@@ -15,7 +15,7 @@ type SenML struct {
WritersPub messaging.Publisher `json:"-"`
}
func (s *SenML) Run(ctx context.Context, msg *messaging.Message, val interface{}) error {
func (s *SenML) Run(ctx context.Context, msg *messaging.Message, val any) error {
// In case there is a single SenML value, convert to slice so we can decode.
if _, ok := val.([]any); !ok {
val = []any{val}
+4 -4
View File
@@ -87,7 +87,7 @@ func (client readersGrpcClient) ReadMessages(ctx context.Context, in *grpcReader
}, nil
}
func decodeReadMessagesResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
func decodeReadMessagesResponse(_ context.Context, grpcRes any) (any, error) {
res := grpcRes.(*grpcReadersV1.ReadMessagesRes)
return readMessagesRes{
Total: res.Total,
@@ -99,7 +99,7 @@ func decodeReadMessagesResponse(_ context.Context, grpcRes interface{}) (interfa
}, nil
}
func encodeReadMessagesRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
func encodeReadMessagesRequest(_ context.Context, grpcReq any) (any, error) {
req := grpcReq.(readMessagesReq)
return &grpcReadersV1.ReadMessagesReq{
ChannelId: req.chanID,
@@ -151,11 +151,11 @@ func fromResponseMessages(protoMessages []*grpcReadersV1.Message) []readers.Mess
case *grpcReadersV1.Message_Json:
j := msg.Json
base := j.GetBase()
var p map[string]interface{}
var p map[string]any
if err := json.Unmarshal(j.GetPayload(), &p); err != nil {
continue
}
messages = append(messages, map[string]interface{}{
messages = append(messages, map[string]any{
"channel": base.GetChannel(),
"created": j.GetCreated(),
"subtopic": base.GetSubtopic(),
+1 -1
View File
@@ -11,7 +11,7 @@ import (
)
func readMessagesEndpoint(svc readers.MessageRepository) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(readMessagesReq)
if err := req.validate(); err != nil {
return readMessagesRes{}, err
+3 -3
View File
@@ -61,20 +61,20 @@ func TestReadMessages(t *testing.T) {
Limit: 10,
},
Messages: []readers.Message{
map[string]interface{}{
map[string]any{
"channel": "testChannel",
"created": int64(123456789),
"subtopic": "testSubtopic",
"publisher": "testPublisher",
"protocol": "testProtocol",
"payload": map[string]interface{}{
"payload": map[string]any{
"temp": 23.5,
},
},
},
}
expectedPayload, err := json.Marshal(tmp.Messages[0].(map[string]interface{})["payload"])
expectedPayload, err := json.Marshal(tmp.Messages[0].(map[string]any)["payload"])
require.NoError(t, err)
expectedRes := &grpcReadersV1.ReadMessagesRes{
+1 -1
View File
@@ -13,4 +13,4 @@ type readMessagesRes struct {
readers.PageMetadata
}
type Message interface{}
type Message any
+5 -5
View File
@@ -31,7 +31,7 @@ func NewReadersServer(svc readers.MessageRepository) grpcReadersV1.ReadersServic
}
}
func decodeReadMessagesRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
func decodeReadMessagesRequest(_ context.Context, grpcReq any) (any, error) {
req := grpcReq.(*grpcReadersV1.ReadMessagesReq)
return readMessagesReq{
chanID: req.GetChannelId(),
@@ -57,7 +57,7 @@ func decodeReadMessagesRequest(_ context.Context, grpcReq interface{}) (interfac
}, nil
}
func encodeReadMessagesResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
func encodeReadMessagesResponse(_ context.Context, grpcRes any) (any, error) {
res := grpcRes.(readMessagesRes)
resp := &grpcReadersV1.ReadMessagesRes{
@@ -105,7 +105,7 @@ func toResponseMessages(messages []readers.Message) []*grpcReadersV1.Message {
},
},
})
case map[string]interface{}:
case map[string]any:
payload := typed["payload"]
data, err := json.Marshal(payload)
if err != nil {
@@ -149,14 +149,14 @@ func stringifyAggregation(agg grpcReadersV1.Aggregation) string {
}
}
func safeString(v interface{}) string {
func safeString(v any) string {
if s, ok := v.(string); ok {
return s
}
return ""
}
func safeInt64(v interface{}) int64 {
func safeInt64(v any) int64 {
switch v := v.(type) {
case float64:
return int64(v)
+1 -1
View File
@@ -17,7 +17,7 @@ import (
)
func listMessagesEndpoint(svc readers.MessageRepository, authn smqauthn.Authentication, clients grpcClientsV1.ClientsServiceClient, channels grpcChannelsV1.ChannelsServiceClient) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(ctx context.Context, request any) (any, error) {
req := request.(listMessagesReq)
if err := req.validate(); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
+2 -2
View File
@@ -67,7 +67,7 @@ func MakeHandler(svc readers.MessageRepository, authn smqauthn.Authentication, c
return mux
}
func decodeList(_ context.Context, r *http.Request) (interface{}, error) {
func decodeList(_ context.Context, r *http.Request) (any, error) {
offset, err := apiutil.ReadNumQuery[uint64](r, offsetKey, defOffset)
if err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
@@ -178,7 +178,7 @@ func decodeList(_ context.Context, r *http.Request) (interface{}, error) {
return req, nil
}
func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
func encodeResponse(_ context.Context, w http.ResponseWriter, response any) error {
w.Header().Set("Content-Type", contentType)
if ar, ok := response.(supermq.Response); ok {
+6 -6
View File
@@ -42,7 +42,7 @@ func (tr postgresRepository) ReadAll(chanID string, rpm readers.PageMetadata) (r
WHERE %s ORDER BY %s DESC
LIMIT :limit OFFSET :offset;`, format, cond, order)
params := map[string]interface{}{
params := map[string]any{
"channel": chanID,
"limit": rpm.Limit,
"offset": rpm.Offset,
@@ -117,7 +117,7 @@ func (tr postgresRepository) ReadAll(chanID string, rpm readers.PageMetadata) (r
func fmtCondition(chanID string, rpm readers.PageMetadata) string {
condition := `channel = :channel`
var query map[string]interface{}
var query map[string]any
meta, err := json.Marshal(rpm)
if err != nil {
return condition
@@ -180,17 +180,17 @@ type jsonMessage struct {
Payload []byte `db:"payload"`
}
func (msg jsonMessage) toMap() (map[string]interface{}, error) {
ret := map[string]interface{}{
func (msg jsonMessage) toMap() (map[string]any, error) {
ret := map[string]any{
"id": msg.ID,
"channel": msg.Channel,
"created": msg.Created,
"subtopic": msg.Subtopic,
"publisher": msg.Publisher,
"protocol": msg.Protocol,
"payload": map[string]interface{}{},
"payload": map[string]any{},
}
pld := make(map[string]interface{})
pld := make(map[string]any)
if err := json.Unmarshal(msg.Payload, &pld); err != nil {
return nil, err
}
+11 -11
View File
@@ -528,12 +528,12 @@ func TestReadJSON(t *testing.T) {
Created: time.Now().Unix(),
Subtopic: "subtopic/format/some_json",
Protocol: "coap",
Payload: map[string]interface{}{
Payload: map[string]any{
"field_1": 123.0,
"field_2": "value",
"field_3": false,
"field_4": 12.344,
"field_5": map[string]interface{}{
"field_5": map[string]any{
"field_1": "value",
"field_2": 42.0,
},
@@ -542,7 +542,7 @@ func TestReadJSON(t *testing.T) {
messages1 := json.Messages{
Format: format1,
}
msgs1 := []map[string]interface{}{}
msgs1 := []map[string]any{}
for i := 0; i < msgsNum; i++ {
msg := m
messages1.Data = append(messages1.Data, msg)
@@ -560,7 +560,7 @@ func TestReadJSON(t *testing.T) {
Created: time.Now().Unix(),
Subtopic: "subtopic/other_format/some_other_json",
Protocol: "udp",
Payload: map[string]interface{}{
Payload: map[string]any{
"field_1": "other_value",
"false_value": false,
"field_pi": 3.14159265,
@@ -569,7 +569,7 @@ func TestReadJSON(t *testing.T) {
messages2 := json.Messages{
Format: format2,
}
msgs2 := []map[string]interface{}{}
msgs2 := []map[string]any{}
for i := 0; i < msgsNum; i++ {
msg := m
if i%2 == 0 {
@@ -583,7 +583,7 @@ func TestReadJSON(t *testing.T) {
err = writer.ConsumeBlocking(context.TODO(), messages2)
require.Nil(t, err, fmt.Sprintf("expected no error got %s\n", err))
httpMsgs := []map[string]interface{}{}
httpMsgs := []map[string]any{}
for i := 0; i < msgsNum; i += 2 {
httpMsgs = append(httpMsgs, msgs2[i])
}
@@ -650,7 +650,7 @@ func TestReadJSON(t *testing.T) {
for i := 0; i < len(result.Messages); i++ {
m := result.Messages[i]
// Remove id as it is not sent by the client.
delete(m.(map[string]interface{}), "id")
delete(m.(map[string]any), "id")
result.Messages[i] = m
}
assert.Nil(t, err, fmt.Sprintf("%s: expected no error got %s", desc, err))
@@ -667,7 +667,7 @@ func fromSenml(msg []senml.Message) []readers.Message {
return ret
}
func fromJSON(msg []map[string]interface{}) []readers.Message {
func fromJSON(msg []map[string]any) []readers.Message {
var ret []readers.Message
for _, m := range msg {
ret = append(ret, m)
@@ -675,13 +675,13 @@ func fromJSON(msg []map[string]interface{}) []readers.Message {
return ret
}
func toMap(msg json.Message) map[string]interface{} {
return map[string]interface{}{
func toMap(msg json.Message) map[string]any {
return map[string]any{
"channel": msg.Channel,
"created": msg.Created,
"subtopic": msg.Subtopic,
"publisher": msg.Publisher,
"protocol": msg.Protocol,
"payload": map[string]interface{}(msg.Payload),
"payload": map[string]any(msg.Payload),
}
}
+6 -6
View File
@@ -70,7 +70,7 @@ func (tr timescaleRepository) ReadAll(chanID string, rpm readers.PageMetadata) (
totalQuery = fmt.Sprintf(`SELECT COUNT(*) FROM (SELECT EXTRACT(epoch FROM time_bucket('%s', to_timestamp(time/%d))) AS time, %s(value) AS value FROM %s WHERE %s GROUP BY 1) AS subquery;`, rpm.Interval, timeDivisor, rpm.Aggregation, format, fmtCondition(rpm))
}
params := map[string]interface{}{
params := map[string]any{
"channel": chanID,
"limit": rpm.Limit,
"offset": rpm.Offset,
@@ -146,7 +146,7 @@ func fmtCondition(rpm readers.PageMetadata) string {
// Indexed columns conditions based on indices order.
chCondition := " channel = :channel "
var query map[string]interface{}
var query map[string]any
meta, err := json.Marshal(rpm)
if err != nil {
return chCondition
@@ -226,16 +226,16 @@ type jsonMessage struct {
Payload []byte `db:"payload"`
}
func (msg jsonMessage) toMap() (map[string]interface{}, error) {
ret := map[string]interface{}{
func (msg jsonMessage) toMap() (map[string]any, error) {
ret := map[string]any{
"channel": msg.Channel,
"created": msg.Created,
"subtopic": msg.Subtopic,
"publisher": msg.Publisher,
"protocol": msg.Protocol,
"payload": map[string]interface{}{},
"payload": map[string]any{},
}
pld := make(map[string]interface{})
pld := make(map[string]any)
if err := json.Unmarshal(msg.Payload, &pld); err != nil {
return nil, err
}
+10 -10
View File
@@ -651,7 +651,7 @@ func TestReadJSON(t *testing.T) {
messages1 := json.Messages{
Format: format1,
}
msgs1 := []map[string]interface{}{}
msgs1 := []map[string]any{}
timeNow := time.Now().UnixMilli()
for i := 0; i < msgsNum; i++ {
m := json.Message{
@@ -660,12 +660,12 @@ func TestReadJSON(t *testing.T) {
Created: timeNow - int64(i),
Subtopic: "subtopic/format/some_json",
Protocol: "coap",
Payload: map[string]interface{}{
Payload: map[string]any{
"field_1": 123.0,
"field_2": "value",
"field_3": false,
"field_4": 12.344,
"field_5": map[string]interface{}{
"field_5": map[string]any{
"field_1": "value",
"field_2": 42.0,
},
@@ -685,7 +685,7 @@ func TestReadJSON(t *testing.T) {
messages2 := json.Messages{
Format: format2,
}
msgs2 := []map[string]interface{}{}
msgs2 := []map[string]any{}
for i := 0; i < msgsNum; i++ {
m := json.Message{
Channel: id2,
@@ -693,7 +693,7 @@ func TestReadJSON(t *testing.T) {
Created: timeNow - int64(i),
Subtopic: "subtopic/other_format/some_other_json",
Protocol: "udp",
Payload: map[string]interface{}{
Payload: map[string]any{
"field_1": "other_value",
"false_value": false,
"field_pi": 3.14159265,
@@ -712,7 +712,7 @@ func TestReadJSON(t *testing.T) {
err = writer.ConsumeBlocking(context.TODO(), messages2)
require.Nil(t, err, fmt.Sprintf("expected no error got %s\n", err))
httpMsgs := []map[string]interface{}{}
httpMsgs := []map[string]any{}
for i := 0; i < msgsNum; i += 2 {
httpMsgs = append(httpMsgs, msgs2[i])
}
@@ -790,7 +790,7 @@ func fromSenml(msg []senml.Message) []readers.Message {
return ret
}
func fromJSON(msg []map[string]interface{}) []readers.Message {
func fromJSON(msg []map[string]any) []readers.Message {
var ret []readers.Message
for _, m := range msg {
ret = append(ret, m)
@@ -798,13 +798,13 @@ func fromJSON(msg []map[string]interface{}) []readers.Message {
return ret
}
func toMap(msg json.Message) map[string]interface{} {
return map[string]interface{}{
func toMap(msg json.Message) map[string]any {
return map[string]any{
"channel": msg.Channel,
"created": msg.Created,
"subtopic": msg.Subtopic,
"publisher": msg.Publisher,
"protocol": msg.Protocol,
"payload": map[string]interface{}(msg.Payload),
"payload": map[string]any(msg.Payload),
}
}
+12 -12
View File
@@ -14,7 +14,7 @@ import (
)
func generateReportEndpoint(svc reports.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.ErrAuthorization
@@ -50,7 +50,7 @@ func generateReportEndpoint(svc reports.Service) endpoint.Endpoint {
}
func listReportsConfigEndpoint(svc reports.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.ErrAuthorization
@@ -78,7 +78,7 @@ func listReportsConfigEndpoint(svc reports.Service) endpoint.Endpoint {
}
func deleteReportConfigEndpoint(svc reports.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.ErrAuthorization
@@ -99,7 +99,7 @@ func deleteReportConfigEndpoint(svc reports.Service) endpoint.Endpoint {
}
func updateReportConfigEndpoint(svc reports.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.ErrAuthorization
@@ -120,7 +120,7 @@ func updateReportConfigEndpoint(svc reports.Service) endpoint.Endpoint {
}
func updateReportScheduleEndpoint(s reports.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.ErrAuthorization
@@ -145,7 +145,7 @@ func updateReportScheduleEndpoint(s reports.Service) endpoint.Endpoint {
}
func viewReportConfigEndpoint(svc reports.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.ErrAuthorization
@@ -166,7 +166,7 @@ func viewReportConfigEndpoint(svc reports.Service) endpoint.Endpoint {
}
func addReportConfigEndpoint(svc reports.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.ErrAuthorization
@@ -190,7 +190,7 @@ func addReportConfigEndpoint(svc reports.Service) endpoint.Endpoint {
}
func enableReportConfigEndpoint(svc reports.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.ErrAuthorization
@@ -211,7 +211,7 @@ func enableReportConfigEndpoint(svc reports.Service) endpoint.Endpoint {
}
func disableReportConfigEndpoint(svc reports.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.ErrAuthorization
@@ -232,7 +232,7 @@ func disableReportConfigEndpoint(svc reports.Service) endpoint.Endpoint {
}
func updateReportTemplateEndpoint(svc reports.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.ErrAuthorization
@@ -253,7 +253,7 @@ func updateReportTemplateEndpoint(svc reports.Service) endpoint.Endpoint {
}
func viewReportTemplateEndpoint(svc reports.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.ErrAuthorization
@@ -274,7 +274,7 @@ func viewReportTemplateEndpoint(svc reports.Service) endpoint.Endpoint {
}
func deleteReportTemplateEndpoint(svc reports.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.ErrAuthorization
+1 -1
View File
@@ -1017,7 +1017,7 @@ func TestUpdateReportTemplateEndpoint(t *testing.T) {
for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
data := toJSON(map[string]interface{}{
data := toJSON(map[string]any{
"report_template": tc.template,
})
req := testRequest{
+12 -12
View File
@@ -133,7 +133,7 @@ func MakeHandler(svc reports.Service, authn mgauthn.Authentication, mux *chi.Mux
return mux
}
func decodeGenerateReportRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeGenerateReportRequest(_ 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)
}
@@ -157,7 +157,7 @@ func decodeGenerateReportRequest(_ context.Context, r *http.Request) (interface{
return req, nil
}
func decodeAddReportConfigRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeAddReportConfigRequest(_ 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)
}
@@ -168,12 +168,12 @@ func decodeAddReportConfigRequest(_ context.Context, r *http.Request) (interface
return addReportConfigReq{ReportConfig: config}, nil
}
func decodeViewReportConfigRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeViewReportConfigRequest(_ context.Context, r *http.Request) (any, error) {
id := chi.URLParam(r, reportIdKey)
return viewReportConfigReq{ID: id}, nil
}
func decodeUpdateReportConfigRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateReportConfigRequest(_ 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)
}
@@ -185,7 +185,7 @@ func decodeUpdateReportConfigRequest(_ context.Context, r *http.Request) (interf
return updateReportConfigReq{ReportConfig: config}, nil
}
func decodeUpdateReportScheduleRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateReportScheduleRequest(_ 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)
}
@@ -200,19 +200,19 @@ func decodeUpdateReportScheduleRequest(_ context.Context, r *http.Request) (inte
return req, nil
}
func decodeUpdateReportStatusRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateReportStatusRequest(_ context.Context, r *http.Request) (any, error) {
req := updateReportStatusReq{
id: chi.URLParam(r, reportIdKey),
}
return req, nil
}
func decodeDeleteReportConfigRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeDeleteReportConfigRequest(_ context.Context, r *http.Request) (any, error) {
id := chi.URLParam(r, reportIdKey)
return deleteReportConfigReq{ID: id}, nil
}
func decodeUpdateReportTemplateRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeUpdateReportTemplateRequest(_ 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)
}
@@ -227,15 +227,15 @@ func decodeUpdateReportTemplateRequest(_ context.Context, r *http.Request) (inte
return req, nil
}
func decodeGetReportTemplateRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeGetReportTemplateRequest(_ context.Context, r *http.Request) (any, error) {
return getReportTemplateReq{ID: chi.URLParam(r, reportIdKey)}, nil
}
func decodeDeleteReportTemplateRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeDeleteReportTemplateRequest(_ context.Context, r *http.Request) (any, error) {
return deleteReportTemplateReq{ID: chi.URLParam(r, reportIdKey)}, nil
}
func decodeListReportsConfigRequest(_ context.Context, r *http.Request) (interface{}, error) {
func decodeListReportsConfigRequest(_ 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)
@@ -276,7 +276,7 @@ func decodeListReportsConfigRequest(_ context.Context, r *http.Request) (interfa
}, nil
}
func encodeFileDownloadResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
func encodeFileDownloadResponse(_ context.Context, w http.ResponseWriter, response any) error {
switch resp := response.(type) {
case downloadReportResp:
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", resp.File.Name))
+2 -2
View File
@@ -36,8 +36,8 @@ func (temp ReportTemplate) Validate() error {
// Validate template syntax using Go's template parser
tmpl := template.New("validate").Funcs(template.FuncMap{
"add": func(a, b int) int { return a + b },
"formatTime": func(t interface{}) string { return "" },
"formatValue": func(v interface{}) string { return "" },
"formatTime": func(t any) string { return "" },
"formatValue": func(v any) string { return "" },
})
parsed, err := tmpl.Parse(templateStr)
+1 -1
View File
@@ -627,7 +627,7 @@ func sendWSMessage(conf Config, msg string, client sdk.Client, chanID string) er
}
// getIDS returns a list of IDs of the given objects.
func getIDS(objects interface{}) string {
func getIDS(objects any) string {
v := reflect.ValueOf(objects)
if v.Kind() != reflect.Slice {
panic("objects argument must be a slice")
+3 -3
View File
@@ -189,7 +189,7 @@ func Provision(ctx context.Context, conf Config) error {
key := ""
if conf.SSL {
var priv interface{}
var priv any
priv, _ = rsa.GenerateKey(rand.Reader, rsaBits)
notBefore := time.Now()
@@ -273,7 +273,7 @@ func Provision(ctx context.Context, conf Config) error {
return nil
}
func publicKey(priv interface{}) interface{} {
func publicKey(priv any) any {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &k.PublicKey
@@ -284,7 +284,7 @@ func publicKey(priv interface{}) interface{} {
}
}
func pemBlockForKey(priv interface{}) *pem.Block {
func pemBlockForKey(priv any) *pem.Block {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(k)}