From 4991ed6ed1b49ae13bdbef605d7918af4734e927 Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Fri, 8 Nov 2019 22:01:59 -0800 Subject: [PATCH] fix linting issues --- db.go | 2 ++ server.go | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/db.go b/db.go index 8d958ed..aceced8 100644 --- a/db.go +++ b/db.go @@ -7,6 +7,8 @@ import "github.com/sneak/merp/models" import "github.com/rs/zerolog/log" import _ "github.com/lib/pq" //revive:disable-line +// GetDB returns an orm.Ormer so that the API server can talk to the +// database func GetDB() orm.Ormer { if os.Getenv("DEBUG") != "" { orm.Debug = true diff --git a/server.go b/server.go index c4ca1d6..976d20a 100644 --- a/server.go +++ b/server.go @@ -17,6 +17,7 @@ import "github.com/thoas/stats" import "github.com/astaxie/beego/orm" import _ "github.com/lib/pq" //revive:disable-line +// Server is the central structure of the HTTP API server. type Server struct { db orm.Ormer debug bool @@ -27,6 +28,7 @@ type Server struct { thingRegex *regexp.Regexp } +// NewServer returns a Server, so that you can run the API. func NewServer() *Server { ms := new(Server) ms.init() @@ -75,7 +77,7 @@ func (ms *Server) ServeForever() { } } -func (ms *Server) HealthCheckHandler() http.HandlerFunc { +func (ms *Server) healthCheckHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { result := gin.H{ "status": "ok", @@ -92,7 +94,7 @@ func (ms *Server) HealthCheckHandler() http.HandlerFunc { } } -func (ms *Server) StatsHandler() http.HandlerFunc { +func (ms *Server) statsHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") stats := ms.stats.Data() @@ -125,10 +127,10 @@ func (ms *Server) setupRoutes() { ms.stats.End(beginning, stats.WithRecorder(recorder)) }) - r.GET("/.well-known/healthcheck.json", gin.WrapF(ms.HealthCheckHandler())) - r.GET("/admin/healthcheck.json", gin.WrapF(ms.HealthCheckHandler())) - r.GET("/admin/stats.json", gin.WrapF(ms.StatsHandler())) - r.GET("/admin/other.json", gin.WrapF(ms.StatsHandler())) + r.GET("/.well-known/healthcheck.json", gin.WrapF(ms.healthCheckHandler())) + r.GET("/admin/healthcheck.json", gin.WrapF(ms.healthCheckHandler())) + r.GET("/admin/stats.json", gin.WrapF(ms.statsHandler())) + r.GET("/admin/other.json", gin.WrapF(ms.statsHandler())) r.GET("/merp/for/:thing", tollbooth_gin.LimitHandler(limiter), ms.handleNewMerp()) r.GET("/get/latest/merp/for/:thing", tollbooth_gin.LimitHandler(limiter), ms.getLatestMerps()) r.GET("/get/latest/merps", tollbooth_gin.LimitHandler(limiter), ms.getLatestMerps())