Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
*.dll
*.so
*.dylib

# Build output
main
go-update

# Test binary, build with `go test -c`
*.test
Expand Down
2 changes: 1 addition & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/brave/go-update/omaha"
"github.com/brave/go-update/omaha/protocol"
"github.com/getsentry/sentry-go"
"github.com/go-chi/chi"
"github.com/go-chi/chi/v5"
"github.com/pressly/lg"
)

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/aws/aws-sdk-go v1.55.7
github.com/brave-intl/bat-go v0.1.0
github.com/getsentry/sentry-go v0.32.0
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-chi/chi/v5 v5.0.12
github.com/go-playground/validator/v10 v10.26.0
github.com/pressly/lg v1.1.1
github.com/sirupsen/logrus v1.9.3
Expand All @@ -20,6 +20,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/getsentry/raven-go v0.2.1-0.20190619092523-5c24d5110e0e // indirect
github.com/go-chi/chi v1.5.5 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/aws/aws-sdk-go v1.55.6 h1:cSg4pvZ3m8dgYcgqB97MrcdjUmZ1BeMYKUxMMB89IPk=
github.com/aws/aws-sdk-go v1.55.6/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aws/aws-sdk-go v1.55.7 h1:UJrkFq7es5CShfBwlWAC8DA077vp8PyVbQd3lqLiztE=
github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand All @@ -18,12 +16,12 @@ github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3G
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
github.com/getsentry/raven-go v0.2.1-0.20190619092523-5c24d5110e0e h1:kpHZPjNRhYcj0G1Y4NryfaoeFF/BSSPd2OwiXbzEMPo=
github.com/getsentry/raven-go v0.2.1-0.20190619092523-5c24d5110e0e/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/getsentry/sentry-go v0.31.1 h1:ELVc0h7gwyhnXHDouXkhqTFSO5oslsRDk0++eyE0KJ4=
github.com/getsentry/sentry-go v0.31.1/go.mod h1:CYNcMMz73YigoHljQRG+qPF+eMq8gG72XcGN/p71BAY=
github.com/getsentry/sentry-go v0.32.0 h1:YKs+//QmwE3DcYtfKRH8/KyOOF/I6Qnx7qYGNHCGmCY=
github.com/getsentry/sentry-go v0.32.0/go.mod h1:CYNcMMz73YigoHljQRG+qPF+eMq8gG72XcGN/p71BAY=
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 v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s=
github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
Expand Down
11 changes: 8 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"log"
"net"
"net/http"
_ "net/http/pprof" // pprof magic
"os"
Expand All @@ -15,8 +16,8 @@ import (
"github.com/brave/go-update/controller"
"github.com/brave/go-update/extension"
"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/pressly/lg"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -76,7 +77,11 @@ func StartServer() {
serverCtx, r := setupRouter(serverCtx, logger, false)
port := ":8192"
fmt.Printf("Starting server: http://localhost%s", port)
srv := http.Server{Addr: port, Handler: chi.ServerBaseContext(serverCtx, r)}
srv := http.Server{
Addr: port,
Handler: r,
BaseContext: func(_ net.Listener) context.Context { return serverCtx },
}
err := srv.ListenAndServe()
if err != nil {
sentry.CaptureException(err)
Expand Down
12 changes: 10 additions & 2 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/brave/go-update/controller"
"github.com/brave/go-update/extension"
"github.com/brave/go-update/extension/extensiontest"
"github.com/go-chi/chi"
"github.com/pressly/lg"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -59,7 +59,15 @@ func init() {
controller.AllExtensionsMap.StoreExtensions(&extension.OfferedExtensions)
controller.ExtensionUpdaterTimeout = time.Millisecond * 1
testCtx, logger := setupLogger(context.Background())
handler = chi.ServerBaseContext(setupRouter(testCtx, logger, true))
_, router := setupRouter(testCtx, logger, true)

// Create a middleware that adds the context with logger to each request
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Add the logger to the context
ctx := lg.WithLoggerContext(r.Context(), logger)
router.ServeHTTP(w, r.WithContext(ctx))
})

controller.RefreshExtensionsTicker(func() {
count++
if count == 1 {
Expand Down