Skip to content

Commit

Permalink
Update module github.com/go-chi/chi to v5 (#157)
Browse files Browse the repository at this point in the history
* Update module github.com/go-chi/chi to v5

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: John Halbert <[email protected]>
  • Loading branch information
renovate[bot] and John Halbert authored Sep 12, 2023
1 parent 30a33d4 commit f9d5df6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/brave/go-sync/datastore"
syncMiddleware "github.com/brave/go-sync/middleware"
"github.com/brave/go-sync/schema/protobuf/sync_pb"
"github.com/go-chi/chi"
"github.com/go-chi/chi/v5"
"github.com/rs/zerolog/log"
"google.golang.org/protobuf/proto"
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/aws/aws-sdk-go v1.45.7
github.com/brave-intl/bat-go v0.5.1
github.com/getsentry/sentry-go v0.24.0
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-chi/chi/v5 v5.0.10
github.com/go-redis/redis/v8 v8.11.5
github.com/prometheus/client_golang v1.16.0
Expand All @@ -22,6 +21,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-chi/chi v4.1.2+incompatible // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
Expand Down
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN
github.com/aws/aws-sdk-go v1.30.27/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
github.com/aws/aws-sdk-go v1.37.19/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go v1.45.6 h1:Y2isQQBZsnO15dzUQo9YQRThtHgrV200XCH05BRHVJI=
github.com/aws/aws-sdk-go v1.45.6/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.45.7 h1:k4QsvWZhm8409TYeRuTV1P6+j3lLKoe+giFA/j3VAps=
github.com/aws/aws-sdk-go v1.45.7/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
Expand Down Expand Up @@ -357,6 +355,7 @@ github.com/go-asn1-ber/asn1-ber v1.5.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkPro
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec=
github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/cors v1.2.0/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
Expand Down
19 changes: 16 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"context"
"fmt"
"net"
"net/http"
_ "net/http/pprof" // pprof magic
"os"
Expand All @@ -20,8 +21,8 @@ import (
"github.com/brave/go-sync/datastore"
"github.com/brave/go-sync/middleware"
sentry "github.com/getsentry/sentry-go"
"github.com/go-chi/chi"
chiware "github.com/go-chi/chi/middleware"
"github.com/go-chi/chi/v5"
chiware "github.com/go-chi/chi/v5/middleware"
"github.com/rs/zerolog"
"github.com/rs/zerolog/hlog"
"github.com/rs/zerolog/log"
Expand All @@ -34,6 +35,8 @@ var (
healthCheckActive = true
)

type baseCtxFunc = func(net.Listener) context.Context

func setupLogger(ctx context.Context) (context.Context, *zerolog.Logger) {
ctx = context.WithValue(ctx, appctx.EnvironmentCTXKey, os.Getenv("ENV"))
ctx = context.WithValue(ctx, appctx.LogLevelCTXKey, zerolog.WarnLevel)
Expand Down Expand Up @@ -104,6 +107,12 @@ func setupRouter(ctx context.Context, logger *zerolog.Logger) (context.Context,
return ctx, r
}

func setupBaseCtx(ctx context.Context) baseCtxFunc {
return func(_ net.Listener) context.Context {
return ctx
}
}

// StartServer starts the translate proxy server on port 8195
func StartServer() {
serverCtx, logger := setupLogger(context.Background())
Expand All @@ -126,7 +135,11 @@ func StartServer() {
serverCtx, r := setupRouter(serverCtx, logger)

port := ":8295"
srv := http.Server{Addr: port, Handler: chi.ServerBaseContext(serverCtx, r)}
srv := http.Server{
Addr: port,
Handler: r,
BaseContext: setupBaseCtx(serverCtx),
}

sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGTERM)
Expand Down
14 changes: 8 additions & 6 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ import (
"testing"

"github.com/brave/go-sync/server"
"github.com/go-chi/chi"
"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/assert"
)

var handler http.Handler
var (
mux *chi.Mux
serverCtx context.Context
)

func init() {
testCtx, logger := server.SetupLogger(context.Background())
serverCtx, mux := server.SetupRouter(testCtx, logger)
handler = chi.ServerBaseContext(serverCtx, mux)
serverCtx, mux = server.SetupRouter(testCtx, logger)
}

func TestPing(t *testing.T) {
req, err := http.NewRequest("GET", "/", nil)
assert.Nil(t, err)

rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
mux.ServeHTTP(rr, req.WithContext(serverCtx))
assert.Equal(t, http.StatusOK, rr.Code)

expected := "."
Expand All @@ -39,7 +41,7 @@ func TestCommand(t *testing.T) {
assert.Nil(t, err)

rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
mux.ServeHTTP(rr, req.WithContext(serverCtx))
assert.Equal(t, http.StatusUnauthorized, rr.Code)
assert.NotEmpty(t, rr.Result().Header.Get("Sane-Time-Millis"))
}

0 comments on commit f9d5df6

Please sign in to comment.