Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Dec 22, 2024
1 parent 8dfa2e6 commit 7722f74
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 38 deletions.
6 changes: 2 additions & 4 deletions internal/client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ import (
"errors"
"unicode"

"github.com/centrifugal/centrifugo/v5/internal/logging"

"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifugo/v5/internal/clientcontext"
"github.com/centrifugal/centrifugo/v5/internal/clientstorage"
"github.com/centrifugal/centrifugo/v5/internal/config"
"github.com/centrifugal/centrifugo/v5/internal/configtypes"
"github.com/centrifugal/centrifugo/v5/internal/jwtverify"
"github.com/centrifugal/centrifugo/v5/internal/logging"
"github.com/centrifugal/centrifugo/v5/internal/proxy"
"github.com/centrifugal/centrifugo/v5/internal/subsource"

"github.com/centrifugal/centrifuge"
"github.com/rs/zerolog/log"
)

// RPCExtensionFunc ...
Expand Down
3 changes: 1 addition & 2 deletions internal/proxy/connect_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (
"encoding/json"
"time"

"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifugo/v5/internal/clientstorage"
"github.com/centrifugal/centrifugo/v5/internal/config"
"github.com/centrifugal/centrifugo/v5/internal/proxyproto"
"github.com/centrifugal/centrifugo/v5/internal/subsource"

"github.com/centrifugal/centrifuge"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
)

// ConnectHandlerConfig ...
Expand Down
3 changes: 1 addition & 2 deletions internal/proxy/publish_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"encoding/base64"
"time"

"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifugo/v5/internal/configtypes"
"github.com/centrifugal/centrifugo/v5/internal/proxyproto"

"github.com/centrifugal/centrifuge"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
)

// PublishHandlerConfig ...
Expand Down
3 changes: 1 addition & 2 deletions internal/proxy/refresh_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"encoding/json"
"time"

"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifugo/v5/internal/proxyproto"

"github.com/centrifugal/centrifuge"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
)

// RefreshHandlerConfig ...
Expand Down
3 changes: 1 addition & 2 deletions internal/proxy/rpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"encoding/base64"
"time"

"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifugo/v5/internal/config"
"github.com/centrifugal/centrifugo/v5/internal/proxyproto"

"github.com/centrifugal/centrifuge"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
)

// RPCHandlerConfig ...
Expand Down
3 changes: 1 addition & 2 deletions internal/proxy/sub_refresh_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"encoding/base64"
"time"

"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifugo/v5/internal/configtypes"
"github.com/centrifugal/centrifugo/v5/internal/proxyproto"

"github.com/centrifugal/centrifuge"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
)

// SubRefreshHandlerConfig ...
Expand Down
3 changes: 1 addition & 2 deletions internal/proxy/subscribe_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"encoding/base64"
"time"

"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifugo/v5/internal/configtypes"
"github.com/centrifugal/centrifugo/v5/internal/proxyproto"
"github.com/centrifugal/centrifugo/v5/internal/subsource"

"github.com/centrifugal/centrifuge"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
)

// SubscribeHandlerConfig ...
Expand Down
3 changes: 1 addition & 2 deletions internal/proxy/subscribe_stream_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import (
"sync"
"time"

"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifugo/v5/internal/configtypes"
"github.com/centrifugal/centrifugo/v5/internal/proxyproto"
"github.com/centrifugal/centrifugo/v5/internal/subsource"

"github.com/centrifugal/centrifuge"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
)

// SubscribeStreamHandlerConfig ...
Expand Down
3 changes: 1 addition & 2 deletions internal/unigrpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"time"

"github.com/centrifugal/centrifugo/v5/internal/logging"
"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifugo/v5/internal/unigrpc/unistream"

"github.com/centrifugal/centrifuge"
"github.com/rs/zerolog/log"
"google.golang.org/grpc"
)

Expand Down
10 changes: 5 additions & 5 deletions internal/unihttpstream/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.Body = http.MaxBytesReader(w, r.Body, maxBytesSize)
connectRequestData, err := io.ReadAll(r.Body)
if err != nil {
log.Info().Err(err).Str("transport", "uni_http_stream").Msg("error reading uni http stream request body")
log.Info().Err(err).Str("transport", transportName).Msg("error reading uni http stream request body")
if len(connectRequestData) >= int(maxBytesSize) {
w.WriteHeader(http.StatusRequestEntityTooLarge)
return
Expand All @@ -52,7 +52,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err = json.Unmarshal(connectRequestData, &req)
if err != nil {
if logging.Enabled(logging.DebugLevel) {
log.Error().Err(err).Str("transport", "uni_http_stream").Msg("malformed connect request")
log.Error().Err(err).Str("transport", transportName).Msg("malformed connect request")
}
return
}
Expand All @@ -64,16 +64,16 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
transport := newStreamTransport(r, h.pingPong)
c, closeFn, err := centrifuge.NewClient(r.Context(), h.node, transport)
if err != nil {
log.Error().Err(err).Str("transport", "uni_http_stream").Msg("error create client")
log.Error().Err(err).Str("transport", transportName).Msg("error create client")
return
}
defer func() { _ = closeFn() }()
defer close(transport.closedCh) // need to execute this after client closeFn.

if logging.Enabled(logging.DebugLevel) {
log.Debug().Str("transport", "uni_http_stream").Str("client", c.ID()).Msg("client connection established")
log.Debug().Str("transport", transportName).Str("client", c.ID()).Msg("client connection established")
defer func(started time.Time) {
log.Debug().Str("transport", "uni_http_stream").Str("client", c.ID()).Dur("duration", time.Since(started)).Msg("client connection completed")
log.Debug().Str("transport", transportName).Str("client", c.ID()).Dur("duration", time.Since(started)).Msg("client connection completed")
}(time.Now())
}

Expand Down
10 changes: 5 additions & 5 deletions internal/unisse/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if connectRequestString != "" {
err := json.Unmarshal([]byte(connectRequestString), &req)
if err != nil {
log.Info().Err(err).Str("transport", "uni_sse").Msg("error unmarshalling connect request")
log.Info().Err(err).Str("transport", transportName).Msg("error unmarshalling connect request")
return
}
} else {
Expand All @@ -62,7 +62,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err = json.Unmarshal(connectRequestData, &req)
if err != nil {
if logging.Enabled(logging.DebugLevel) {
log.Debug().Err(err).Str("transport", "uni_sse").Msg("malformed connect request")
log.Debug().Err(err).Str("transport", transportName).Msg("malformed connect request")
}
return
}
Expand All @@ -74,16 +74,16 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
transport := newEventsourceTransport(r, h.pingPong)
c, closeFn, err := centrifuge.NewClient(r.Context(), h.node, transport)
if err != nil {
log.Error().Err(err).Str("transport", "uni_sse").Msg("error create client")
log.Error().Err(err).Str("transport", transportName).Msg("error create client")
return
}
defer func() { _ = closeFn() }()
defer close(transport.closedCh) // need to execute this after client closeFn.

if logging.Enabled(logging.DebugLevel) {
log.Debug().Str("transport", "uni_sse").Str("client", c.ID()).Msg("client connection established")
log.Debug().Str("transport", transportName).Str("client", c.ID()).Msg("client connection established")
defer func(started time.Time) {
log.Debug().Str("transport", "uni_sse").Str("client", c.ID()).Dur("duration", time.Since(started)).Msg("client connection completed")
log.Debug().Str("transport", transportName).Str("client", c.ID()).Dur("duration", time.Since(started)).Msg("client connection completed")
}(time.Now())
}

Expand Down
11 changes: 5 additions & 6 deletions internal/uniws/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (

"github.com/centrifugal/centrifugo/v5/internal/logging"

"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifuge"
"github.com/centrifugal/protocol"
"github.com/gorilla/websocket"
"github.com/rs/zerolog/log"
)

// Handler handles WebSocket client connections. Usually WebSocket protocol
Expand Down Expand Up @@ -75,7 +74,7 @@ func (s *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {

conn, err := s.upgrade.Upgrade(rw, r, nil)
if err != nil {
log.Error().Err(err).Str("transport", "uni_ws").Msg("websocket upgrade error")
log.Error().Err(err).Str("transport", transportName).Msg("websocket upgrade error")
return
}

Expand Down Expand Up @@ -135,15 +134,15 @@ func (s *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {

c, closeFn, err := centrifuge.NewClient(NewCancelContext(r.Context(), ctxCh), s.node, transport)
if err != nil {
log.Error().Err(err).Str("transport", "uni_ws").Msg("error creating client")
log.Error().Err(err).Str("transport", transportName).Msg("error creating client")
return
}
defer func() { _ = closeFn() }()

if logging.Enabled(logging.DebugLevel) {
log.Debug().Str("transport", "uni_ws").Str("client", c.ID()).Msg("client connection established")
log.Debug().Str("transport", transportName).Str("client", c.ID()).Msg("client connection established")
defer func(started time.Time) {
log.Debug().Str("transport", "uni_ws").Str("client", c.ID()).Dur("duration", time.Since(started)).Msg("client connection completed")
log.Debug().Str("transport", transportName).Str("client", c.ID()).Dur("duration", time.Since(started)).Msg("client connection completed")
}(time.Now())
}

Expand Down
3 changes: 1 addition & 2 deletions internal/wt/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (

"github.com/centrifugal/centrifugo/v5/internal/logging"

"github.com/rs/zerolog/log"

"github.com/centrifugal/centrifuge"
"github.com/centrifugal/protocol"
"github.com/quic-go/webtransport-go"
"github.com/rs/zerolog/log"
)

// Handler for WebTransport.
Expand Down

0 comments on commit 7722f74

Please sign in to comment.