Skip to content

Commit 9d31f2a

Browse files
authored
Merge pull request #2262 from alexandear/remove-gorilla-mux
Replace github.com/gorilla/mux with net/http
2 parents 982ef56 + a6fc632 commit 9d31f2a

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

cmd/limactl/hostagent.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"strconv"
1313
"syscall"
1414

15-
"github.com/gorilla/mux"
1615
"github.com/lima-vm/lima/pkg/hostagent"
1716
"github.com/lima-vm/lima/pkg/hostagent/api/server"
1817
"github.com/sirupsen/logrus"
@@ -91,7 +90,7 @@ func hostagentAction(cmd *cobra.Command, args []string) error {
9190
backend := &server.Backend{
9291
Agent: ha,
9392
}
94-
r := mux.NewRouter()
93+
r := http.NewServeMux()
9594
server.AddRoutes(r, backend)
9695
srv := &http.Server{Handler: r}
9796
err = os.RemoveAll(socket)

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ require (
2323
github.com/foxcpp/go-mockdns v1.1.0
2424
github.com/goccy/go-yaml v1.11.3
2525
github.com/google/go-cmp v0.6.0
26-
github.com/gorilla/mux v1.8.1
2726
github.com/lima-vm/go-qcow2reader v0.1.1
2827
github.com/lima-vm/sshocker v0.3.4
2928
github.com/mattn/go-isatty v0.0.20

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLe
124124
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
125125
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
126126
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
127-
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
128-
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
129127
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
130128
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
131129
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=

pkg/hostagent/api/server/server.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"net/http"
77

8-
"github.com/gorilla/mux"
98
"github.com/lima-vm/lima/pkg/hostagent"
109
"github.com/lima-vm/lima/pkg/httputil"
1110
)
@@ -25,8 +24,13 @@ func (b *Backend) onError(w http.ResponseWriter, err error, ec int) {
2524
_ = json.NewEncoder(w).Encode(e)
2625
}
2726

28-
// GetInfo is the handler for GET /v{N}/info
27+
// GetInfo is the handler for GET /v1/info
2928
func (b *Backend) GetInfo(w http.ResponseWriter, r *http.Request) {
29+
if r.Method != http.MethodGet {
30+
w.WriteHeader(http.StatusMethodNotAllowed)
31+
return
32+
}
33+
3034
ctx := r.Context()
3135
ctx, cancel := context.WithCancel(ctx)
3236
defer cancel()
@@ -46,7 +50,6 @@ func (b *Backend) GetInfo(w http.ResponseWriter, r *http.Request) {
4650
_, _ = w.Write(m)
4751
}
4852

49-
func AddRoutes(r *mux.Router, b *Backend) {
50-
v1 := r.PathPrefix("/v1").Subrouter()
51-
v1.Path("/info").Methods("GET").HandlerFunc(b.GetInfo)
53+
func AddRoutes(r *http.ServeMux, b *Backend) {
54+
r.Handle("/v1/info", http.HandlerFunc(b.GetInfo))
5255
}

0 commit comments

Comments
 (0)