Skip to content

Commit

Permalink
Implement HTTP server via gorilla mux.
Browse files Browse the repository at this point in the history
This is mainly so we can keep supporting Go < 1.22 which is still
a tiny bit too new for me to assume as default for every Go dev.
However, I would love to drop this dependency once we have
moved on in the future.
  • Loading branch information
icedream committed Mar 15, 2024
1 parent e30c025 commit 684d581
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cmd/storage/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (
"io"
"net/http"
"strconv"

"github.com/gorilla/mux"
)

func newHTTPServiceHandler() http.Handler {
mux := http.NewServeMux()
mux.Handle("/download/{path}", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requestedPath := r.PathValue("path")
r := mux.NewRouter()
r.Get("/download/{path}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
requestedPath := vars["path"]
if requestedPath != demoTrackURL {
w.WriteHeader(http.StatusNotFound)
return
Expand All @@ -19,9 +22,9 @@ func newHTTPServiceHandler() http.Handler {
w.WriteHeader(http.StatusOK)
f := bytes.NewReader(demoTrackBytes)
io.Copy(w, f)
}))
mux.Handle("/ping", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
})
r.Get("/ping").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}))
return mux
})
return r
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require (
github.com/google/cel-go v0.20.1 // indirect
github.com/google/go-containerregistry v0.19.0 // indirect
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jdx/go-netrc v1.0.0 // indirect
github.com/klauspost/compress v1.17.7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,8 @@ github.com/googleapis/gax-go/v2 v2.11.0/go.mod h1:DxmR61SGKkGLa2xigwuZIQpkCI2S5i
github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU=
github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks=
Expand Down

0 comments on commit 684d581

Please sign in to comment.