Skip to content

Commit

Permalink
Use request logger in routes/provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Jan 3, 2024
1 parent 3730e3c commit 84cdacd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 7 additions & 4 deletions internal/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/go-chi/chi/v5"
"github.com/gorilla/websocket"
"github.com/rs/zerolog/hlog"

"github.com/beeper/registration-relay/internal/provider"
)
Expand All @@ -19,7 +20,7 @@ func (a *api) bridgeExecuteCommand(w http.ResponseWriter, r *http.Request) {
return
}

log := a.log.With().Str("code", code).Logger()
log := hlog.FromRequest(r).With().Str("code", code).Logger()

provider, exists := provider.GetProvider(code)
if !exists {
Expand All @@ -42,16 +43,18 @@ func (a *api) bridgeExecuteCommand(w http.ResponseWriter, r *http.Request) {
}

func (a *api) providerWebsocket(w http.ResponseWriter, r *http.Request) {
log := hlog.FromRequest(r)

conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
a.log.Err(err).Msg("Failed to upgrade websocket connection")
log.Err(err).Msg("Failed to upgrade websocket connection")
w.WriteHeader(http.StatusInternalServerError)
return
}
defer conn.Close()

provider := provider.NewProvider(conn, a.secret)
provider := provider.NewProvider(conn, a.secret, log)
provider.WebsocketLoop()

a.log.Info().Msg("Websocket connection closed")
log.Info().Msg("Websocket connection closed")
}
3 changes: 1 addition & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/gorilla/websocket"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/beeper/registration-relay/internal/metrics"
"github.com/beeper/registration-relay/internal/util"
Expand Down Expand Up @@ -101,7 +100,7 @@ type provider struct {
globalSecret []byte
}

func NewProvider(ws *websocket.Conn, secret []byte) *provider {
func NewProvider(ws *websocket.Conn, secret []byte, log *zerolog.Logger) *provider {
logger := log.With().
Str("component", "provider").
Logger()
Expand Down

0 comments on commit 84cdacd

Please sign in to comment.