Skip to content

Commit c35c925

Browse files
committed
Switch to native Go router
Signed-off-by: Stéphane Graber <[email protected]>
1 parent 7d5de63 commit c35c925

File tree

8 files changed

+18
-25
lines changed

8 files changed

+18
-25
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
github.com/armon/go-proxyproto v0.1.0
77
github.com/fsnotify/fsnotify v1.9.0
88
github.com/goccy/go-yaml v1.17.1
9-
github.com/gorilla/mux v1.8.1
109
github.com/gorilla/websocket v1.5.3
1110
github.com/inconshreveable/log15 v2.16.0+incompatible
1211
github.com/lib/pq v1.10.9

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX
2121
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2222
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
2323
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
24-
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
25-
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
2624
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
2725
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
2826
github.com/inconshreveable/log15 v2.16.0+incompatible h1:6nvMKxtGcpgm7q0KiGs+Vc+xDvUXaBqsPKHWKsinccw=

internal/daemon/daemon.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"time"
1414

1515
"github.com/armon/go-proxyproto"
16-
"github.com/gorilla/mux"
1716
"github.com/inconshreveable/log15"
1817
"github.com/prometheus/client_golang/prometheus/promhttp"
1918

@@ -33,7 +32,7 @@ type Daemon struct {
3332
db *database.DB
3433

3534
// Request router
36-
router *mux.Router
35+
router *http.ServeMux
3736

3837
// Log handler
3938
logger log15.Logger
@@ -125,7 +124,7 @@ func (d *Daemon) Run() error {
125124
d.config.ConfigPut = *dbConf
126125

127126
// Setup the REST API
128-
d.router = mux.NewRouter()
127+
d.router = http.NewServeMux()
129128
err = rest.AttachFunctions(
130129
d.config,
131130
d.router,
@@ -239,7 +238,7 @@ func (d *Daemon) Run() error {
239238

240239
d.logger.Info("Binding Prometheus", log15.Ctx{"port": d.config.Daemon.PrometheusPort})
241240
go func() {
242-
router := mux.NewRouter()
241+
router := http.NewServeMux()
243242
router.Handle("/metrics", promhttp.Handler())
244243

245244
server := &http.Server{

internal/rest/api_flags.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strconv"
1111
"time"
1212

13-
"github.com/gorilla/mux"
1413
"github.com/inconshreveable/log15"
1514

1615
"github.com/nsec/askgod/api"
@@ -53,7 +52,7 @@ func (r *rest) getTeamFlags(writer http.ResponseWriter, request *http.Request, l
5352
}
5453

5554
func (r *rest) getTeamFlag(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
56-
idVar := mux.Vars(request)["id"]
55+
idVar := request.PathValue("id")
5756

5857
// Convert the provided id to int
5958
id, err := strconv.ParseInt(idVar, 10, 64)
@@ -100,7 +99,7 @@ func (r *rest) getTeamFlag(writer http.ResponseWriter, request *http.Request, lo
10099
}
101100

102101
func (r *rest) updateTeamFlag(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
103-
idVar := mux.Vars(request)["id"]
102+
idVar := request.PathValue("id")
104103

105104
// Convert the provided id to int
106105
id, err := strconv.ParseInt(idVar, 10, 64)
@@ -343,7 +342,7 @@ func (r *rest) adminCreateFlags(writer http.ResponseWriter, request *http.Reques
343342
}
344343

345344
func (r *rest) adminGetFlag(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
346-
idVar := mux.Vars(request)["id"]
345+
idVar := request.PathValue("id")
347346

348347
// Convert the provided id to int
349348
id, err := strconv.ParseInt(idVar, 10, 64)
@@ -372,7 +371,7 @@ func (r *rest) adminGetFlag(writer http.ResponseWriter, request *http.Request, l
372371
}
373372

374373
func (r *rest) adminUpdateFlag(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
375-
idVar := mux.Vars(request)["id"]
374+
idVar := request.PathValue("id")
376375

377376
// Convert the provided id to int
378377
id, err := strconv.ParseInt(idVar, 10, 64)
@@ -411,7 +410,7 @@ func (r *rest) adminUpdateFlag(writer http.ResponseWriter, request *http.Request
411410
}
412411

413412
func (r *rest) adminDeleteFlag(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
414-
idVar := mux.Vars(request)["id"]
413+
idVar := request.PathValue("id")
415414

416415
// Convert the provided id to int
417416
id, err := strconv.ParseInt(idVar, 10, 64)

internal/rest/api_scores.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strconv"
1010
"time"
1111

12-
"github.com/gorilla/mux"
1312
"github.com/inconshreveable/log15"
1413

1514
"github.com/nsec/askgod/api"
@@ -121,7 +120,7 @@ func (r *rest) adminCreateScoreCommon(writer http.ResponseWriter, request *http.
121120
}
122121

123122
func (r *rest) adminGetScore(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
124-
idVar := mux.Vars(request)["id"]
123+
idVar := request.PathValue("id")
125124

126125
// Convert the provided id to int
127126
id, err := strconv.ParseInt(idVar, 10, 64)
@@ -150,7 +149,7 @@ func (r *rest) adminGetScore(writer http.ResponseWriter, request *http.Request,
150149
}
151150

152151
func (r *rest) adminUpdateScore(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
153-
idVar := mux.Vars(request)["id"]
152+
idVar := request.PathValue("id")
154153

155154
// Convert the provided id to int
156155
id, err := strconv.ParseInt(idVar, 10, 64)
@@ -238,7 +237,7 @@ func (r *rest) adminUpdateScore(writer http.ResponseWriter, request *http.Reques
238237
}
239238

240239
func (r *rest) adminDeleteScore(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
241-
idVar := mux.Vars(request)["id"]
240+
idVar := request.PathValue("id")
242241

243242
// Convert the provided id to int
244243
id, err := strconv.ParseInt(idVar, 10, 64)

internal/rest/api_teams.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strconv"
1212
"strings"
1313

14-
"github.com/gorilla/mux"
1514
"github.com/inconshreveable/log15"
1615

1716
"github.com/nsec/askgod/api"
@@ -251,7 +250,7 @@ func (r *rest) adminCreateTeams(writer http.ResponseWriter, request *http.Reques
251250
}
252251

253252
func (r *rest) adminGetTeam(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
254-
idVar := mux.Vars(request)["id"]
253+
idVar := request.PathValue("id")
255254

256255
// Convert the provided id to int
257256
id, err := strconv.ParseInt(idVar, 10, 64)
@@ -280,7 +279,7 @@ func (r *rest) adminGetTeam(writer http.ResponseWriter, request *http.Request, l
280279
}
281280

282281
func (r *rest) adminUpdateTeam(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
283-
idVar := mux.Vars(request)["id"]
282+
idVar := request.PathValue("id")
284283

285284
// Convert the provided id to int
286285
id, err := strconv.ParseInt(idVar, 10, 64)
@@ -320,7 +319,7 @@ func (r *rest) adminUpdateTeam(writer http.ResponseWriter, request *http.Request
320319
}
321320

322321
func (r *rest) adminDeleteTeam(writer http.ResponseWriter, request *http.Request, logger log15.Logger) {
323-
idVar := mux.Vars(request)["id"]
322+
idVar := request.PathValue("id")
324323

325324
// Convert the provided id to int
326325
id, err := strconv.ParseInt(idVar, 10, 64)

internal/rest/attach.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/url"
77
"strings"
88

9-
"github.com/gorilla/mux"
109
"github.com/inconshreveable/log15"
1110

1211
"github.com/nsec/askgod/internal/config"
@@ -16,7 +15,7 @@ import (
1615
var clusterPeers []string
1716

1817
// AttachFunctions attaches all the REST API functions to the provided router.
19-
func AttachFunctions(conf *config.Config, router *mux.Router, db *database.DB, logger log15.Logger) error {
18+
func AttachFunctions(conf *config.Config, router *http.ServeMux, db *database.DB, logger log15.Logger) error {
2019
r := rest{
2120
config: conf,
2221
db: db,

internal/rest/struct.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package rest
22

33
import (
4-
"github.com/gorilla/mux"
4+
"net/http"
5+
56
"github.com/inconshreveable/log15"
67

78
"github.com/nsec/askgod/internal/config"
@@ -12,6 +13,6 @@ type rest struct {
1213
config *config.Config
1314
db *database.DB
1415
logger log15.Logger
15-
router *mux.Router
16+
router *http.ServeMux
1617
hiddenTeams []int64
1718
}

0 commit comments

Comments
 (0)