Skip to content

Commit

Permalink
replace interface{} with any (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia authored Jul 28, 2023
1 parent 54f7d22 commit 5959936
Show file tree
Hide file tree
Showing 35 changed files with 197 additions and 197 deletions.
34 changes: 17 additions & 17 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (h *Executor) Publish(ctx context.Context, cmd *PublishRequest) *PublishRes
centrifuge.WithTags(cmd.GetTags()),
)
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error publishing message in engine", map[string]interface{}{"error": err.Error(), "channel": cmd.Channel}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error publishing message in engine", map[string]any{"error": err.Error(), "channel": cmd.Channel}))
resp.Error = ErrorInternal
return resp
}
Expand Down Expand Up @@ -228,12 +228,12 @@ func (h *Executor) Broadcast(ctx context.Context, cmd *BroadcastRequest) *Broadc

_, _, chOpts, found, err := h.ruleContainer.ChannelOptions(ch)
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error getting options for channel", map[string]interface{}{"channel": ch, "error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error getting options for channel", map[string]any{"channel": ch, "error": err.Error()}))
responses[i] = &PublishResponse{Error: ErrorInternal}
return
}
if !found {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "can't find namespace for channel", map[string]interface{}{"channel": ch}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "can't find namespace for channel", map[string]any{"channel": ch}))
responses[i] = &PublishResponse{Error: ErrorUnknownChannel}
return
}
Expand All @@ -258,7 +258,7 @@ func (h *Executor) Broadcast(ctx context.Context, cmd *BroadcastRequest) *Broadc
Epoch: result.StreamPosition.Epoch,
}
} else {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error publishing data to channel", map[string]interface{}{"channel": ch, "error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error publishing data to channel", map[string]any{"channel": ch, "error": err.Error()}))
resp.Error = ErrorInternal
}
responses[i] = resp
Expand All @@ -280,7 +280,7 @@ func (h *Executor) Subscribe(_ context.Context, cmd *SubscribeRequest) *Subscrib
channel := cmd.Channel

if channel == "" {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "channel required for subscribe", map[string]interface{}{"channel": channel, "user": user}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "channel required for subscribe", map[string]any{"channel": channel, "user": user}))
resp.Error = ErrorBadRequest
return resp
}
Expand Down Expand Up @@ -340,7 +340,7 @@ func (h *Executor) Subscribe(_ context.Context, cmd *SubscribeRequest) *Subscrib
centrifuge.WithSubscribeHistoryMetaTTL(time.Duration(chOpts.HistoryMetaTTL)),
)
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error subscribing user to a channel", map[string]interface{}{"channel": channel, "user": user, "error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error subscribing user to a channel", map[string]any{"channel": channel, "user": user, "error": err.Error()}))
resp.Error = ErrorInternal
return resp
}
Expand Down Expand Up @@ -372,7 +372,7 @@ func (h *Executor) Unsubscribe(_ context.Context, cmd *UnsubscribeRequest) *Unsu

err := h.node.Unsubscribe(user, channel, centrifuge.WithUnsubscribeClient(cmd.Client), centrifuge.WithUnsubscribeSession(cmd.Session))
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error unsubscribing user from a channel", map[string]interface{}{"channel": channel, "user": user, "error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error unsubscribing user from a channel", map[string]any{"channel": channel, "user": user, "error": err.Error()}))
resp.Error = ErrorInternal
return resp
}
Expand Down Expand Up @@ -404,7 +404,7 @@ func (h *Executor) Disconnect(_ context.Context, cmd *DisconnectRequest) *Discon
centrifuge.WithDisconnectSession(cmd.Session),
centrifuge.WithDisconnectClientWhitelist(cmd.Whitelist))
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error disconnecting user", map[string]interface{}{"user": cmd.User, "error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error disconnecting user", map[string]any{"user": cmd.User, "error": err.Error()}))
resp.Error = ErrorInternal
return resp
}
Expand All @@ -428,7 +428,7 @@ func (h *Executor) Refresh(_ context.Context, cmd *RefreshRequest) *RefreshRespo
centrifuge.WithRefreshInfo(cmd.Info),
)
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error refreshing user", map[string]interface{}{"user": cmd.User, "error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error refreshing user", map[string]any{"user": cmd.User, "error": err.Error()}))
resp.Error = ErrorInternal
return resp
}
Expand Down Expand Up @@ -466,7 +466,7 @@ func (h *Executor) Presence(_ context.Context, cmd *PresenceRequest) *PresenceRe

presence, err := h.node.Presence(ch)
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling presence", map[string]interface{}{"error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling presence", map[string]any{"error": err.Error()}))
resp.Error = ErrorInternal
return resp
}
Expand Down Expand Up @@ -517,7 +517,7 @@ func (h *Executor) PresenceStats(_ context.Context, cmd *PresenceStatsRequest) *

stats, err := h.node.PresenceStats(cmd.Channel)
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling presence stats", map[string]interface{}{"error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling presence stats", map[string]any{"error": err.Error()}))
resp.Error = ErrorInternal
return resp
}
Expand Down Expand Up @@ -576,7 +576,7 @@ func (h *Executor) History(_ context.Context, cmd *HistoryRequest) *HistoryRespo
centrifuge.WithReverse(cmd.Reverse),
)
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling history", map[string]interface{}{"error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling history", map[string]any{"error": err.Error()}))
if errors.Is(err, centrifuge.ErrorUnrecoverablePosition) {
resp.Error = ErrorUnrecoverablePosition
return resp
Expand Down Expand Up @@ -642,7 +642,7 @@ func (h *Executor) HistoryRemove(_ context.Context, cmd *HistoryRemoveRequest) *

err = h.node.RemoveHistory(ch)
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling history remove", map[string]interface{}{"error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling history remove", map[string]any{"error": err.Error()}))
resp.Error = ErrorInternal
return resp
}
Expand All @@ -658,7 +658,7 @@ func (h *Executor) Info(_ context.Context, _ *InfoRequest) *InfoResponse {

info, err := h.node.Info()
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling info", map[string]interface{}{"error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling info", map[string]any{"error": err.Error()}))
resp.Error = ErrorInternal
return resp
}
Expand Down Expand Up @@ -698,7 +698,7 @@ func (h *Executor) RPC(ctx context.Context, cmd *RPCRequest) *RPCResponse {
resp := &RPCResponse{}

if cmd.Method == "" {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "rpc method required", map[string]interface{}{}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "rpc method required", map[string]any{}))
resp.Error = ErrorBadRequest
return resp
}
Expand All @@ -713,7 +713,7 @@ func (h *Executor) RPC(ctx context.Context, cmd *RPCRequest) *RPCResponse {

data, err := handler(ctx, cmd.Params)
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error sending rpc", map[string]interface{}{"error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error sending rpc", map[string]any{"error": err.Error()}))
resp.Error = toAPIErr(err)
return resp
}
Expand All @@ -734,7 +734,7 @@ func (h *Executor) Channels(ctx context.Context, cmd *ChannelsRequest) *Channels

channels, err := h.surveyCaller.Channels(ctx, cmd)
if err != nil {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling channels", map[string]interface{}{"error": err.Error()}))
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error calling channels", map[string]any{"error": err.Error()}))
resp.Error = toAPIErr(err)
return resp
}
Expand Down
2 changes: 1 addition & 1 deletion internal/api/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func authorize(ctx context.Context, key []byte) error {
// `apikey <KEY>`.
func GRPCKeyAuth(key string) grpc.ServerOption {
authKey := []byte("apikey " + key)
return grpc.UnaryInterceptor(func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
return grpc.UnaryInterceptor(func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
if err := authorize(ctx, authKey); err != nil {
return nil, err
}
Expand Down
38 changes: 19 additions & 19 deletions internal/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (s *Handler) handleAPI(w http.ResponseWriter, r *http.Request) {

data, err = io.ReadAll(r.Body)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error reading API request body", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error reading API request body", map[string]any{"error": err.Error()}))
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
Expand All @@ -99,7 +99,7 @@ func (s *Handler) handleAPI(w http.ResponseWriter, r *http.Request) {
for {
command, decodeErr := decoder.Decode()
if decodeErr != nil && decodeErr != io.EOF {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding API data", map[string]interface{}{"error": decodeErr.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding API data", map[string]any{"error": decodeErr.Error()}))
http.Error(w, "Bad Request", http.StatusBadRequest)
return
}
Expand All @@ -114,7 +114,7 @@ func (s *Handler) handleAPI(w http.ResponseWriter, r *http.Request) {
span := trace.SpanFromContext(r.Context())
span.SetStatus(codes.Error, err.Error())
}
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error handling API command", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error handling API command", map[string]any{"error": err.Error()}))
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
Expand All @@ -124,7 +124,7 @@ func (s *Handler) handleAPI(w http.ResponseWriter, r *http.Request) {
}
err = encoder.Encode(rep)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error encoding API reply", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error encoding API reply", map[string]any{"error": err.Error()}))
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_PUBLISH:
cmd, err := decoder.DecodePublish(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding publish params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding publish params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -175,7 +175,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_BROADCAST:
cmd, err := decoder.DecodeBroadcast(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding broadcast params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding broadcast params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -193,7 +193,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_SUBSCRIBE:
cmd, err := decoder.DecodeSubscribe(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding subscribe params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding subscribe params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -211,7 +211,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_UNSUBSCRIBE:
cmd, err := decoder.DecodeUnsubscribe(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding unsubscribe params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding unsubscribe params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -229,7 +229,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_DISCONNECT:
cmd, err := decoder.DecodeDisconnect(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding disconnect params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding disconnect params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -247,7 +247,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_PRESENCE:
cmd, err := decoder.DecodePresence(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding presence params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding presence params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -265,7 +265,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_PRESENCE_STATS:
cmd, err := decoder.DecodePresenceStats(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding presence stats params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding presence stats params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -283,7 +283,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_HISTORY:
cmd, err := decoder.DecodeHistory(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding history params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding history params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -301,7 +301,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_HISTORY_REMOVE:
cmd, err := decoder.DecodeHistoryRemove(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding history remove params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding history remove params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand Down Expand Up @@ -332,7 +332,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_RPC:
cmd, err := decoder.DecodeRPC(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding rpc params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding rpc params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -350,7 +350,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_REFRESH:
cmd, err := decoder.DecodeRefresh(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding refresh params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding refresh params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -368,7 +368,7 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
case Command_CHANNELS:
cmd, err := decoder.DecodeChannels(params)
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding channels params", map[string]interface{}{"error": err.Error()}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding channels params", map[string]any{"error": err.Error()}))
rep.Error = ErrorBadRequest
return rep, nil
}
Expand All @@ -395,17 +395,17 @@ func (s *Handler) handleAPICommand(ctx context.Context, cmd *Command) (*Reply, e
}

func (s *Handler) handleReadDataError(r *http.Request, w http.ResponseWriter, err error) {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error reading API request body", map[string]interface{}{"error": err.Error(), "path": r.URL.Path}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error reading API request body", map[string]any{"error": err.Error(), "path": r.URL.Path}))
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}

func (s *Handler) handleUnmarshalError(r *http.Request, w http.ResponseWriter, err error) {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding API request body", map[string]interface{}{"error": err.Error(), "path": r.URL.Path}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding API request body", map[string]any{"error": err.Error(), "path": r.URL.Path}))
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
}

func (s *Handler) handleMarshalError(r *http.Request, w http.ResponseWriter, err error) {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error encoding API response", map[string]interface{}{"error": err.Error(), "path": r.URL.Path}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error encoding API response", map[string]any{"error": err.Error(), "path": r.URL.Path}))
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}

Expand Down
Loading

0 comments on commit 5959936

Please sign in to comment.