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