From 3742acf14981fba2034cb4df1a209744afefa8cd Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sat, 26 Oct 2024 01:06:24 +0200 Subject: [PATCH] Replace Gorilla Mux with net/http router --- go.mod | 7 ++----- go.sum | 2 -- idicon.go | 9 ++++----- idicon_test.go | 6 ++---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index ac5cc66..de796a4 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,5 @@ module idicon -go 1.20 +go 1.22 -require ( - github.com/BurntSushi/toml v1.4.0 - github.com/gorilla/mux v1.8.1 -) +require github.com/BurntSushi/toml v1.4.0 diff --git a/go.sum b/go.sum index 3160ef1..8bc10f6 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,2 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= -github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= -github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= diff --git a/idicon.go b/idicon.go index b104c2b..b0e9ffb 100644 --- a/idicon.go +++ b/idicon.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "github.com/BurntSushi/toml" - "github.com/gorilla/mux" "idicon/icons" "image/gif" "image/jpeg" @@ -26,7 +25,7 @@ func pageRequestHandler(w http.ResponseWriter, _ *http.Request) { } func requestHandler(w http.ResponseWriter, r *http.Request) { - id := mux.Vars(r)["id"] + id := r.PathValue("id") size, err := strconv.Atoi(r.URL.Query().Get("s")) if err != nil { @@ -135,9 +134,9 @@ func main() { configure(*configFile) - router := mux.NewRouter() - router.HandleFunc("/avatar", pageRequestHandler) - router.HandleFunc("/avatar/{id}", requestHandler) + router := http.NewServeMux() + router.HandleFunc("GET /avatar", pageRequestHandler) + router.HandleFunc("GET /avatar/{id}", requestHandler) log.Printf("Starting on port %d ...\n", *port) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), router)) } diff --git a/idicon_test.go b/idicon_test.go index 65f0e04..566f110 100644 --- a/idicon_test.go +++ b/idicon_test.go @@ -7,8 +7,6 @@ import ( "os" "reflect" "testing" - - "github.com/gorilla/mux" ) //go:embed testdata/1a79a4d60de6718e8e5b326e338ae533_v1.png @@ -26,8 +24,8 @@ var gh2 []byte //go:embed testdata/1a79a4d60de6718e8e5b326e338ae533_s40.png var s40 []byte -func testRouter() *mux.Router { - router := mux.NewRouter() +func testRouter() *http.ServeMux { + router := http.NewServeMux() router.HandleFunc("/avatar/{id}", requestHandler) return router }