From a6d2b0ed1770b96967193b4d2ae9e59fd9209e55 Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Fri, 8 Nov 2019 21:59:16 -0800 Subject: [PATCH] renamed type as recommended to avoid stuttering --- cmd/merp/main.go | 2 +- merp.go | 4 ++-- server.go | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/merp/main.go b/cmd/merp/main.go index 4fced82..e6b46b5 100644 --- a/cmd/merp/main.go +++ b/cmd/merp/main.go @@ -25,7 +25,7 @@ func main() { wg.Add(1) go func() { - ms := merp.NewMerpServer() + ms := merp.NewServer() ms.ServeForever() wg.Done() }() diff --git a/merp.go b/merp.go index a514319..63b59ea 100644 --- a/merp.go +++ b/merp.go @@ -20,7 +20,7 @@ func decodeJSON(in []byte) (interface{}, error) { return out, nil } -func (ms *MerpServer) getLatestMerps() gin.HandlerFunc { +func (ms *Server) getLatestMerps() gin.HandlerFunc { return func(c *gin.Context) { thing := c.Param("thing") if thing != "" { @@ -67,7 +67,7 @@ func (ms *MerpServer) getLatestMerps() gin.HandlerFunc { } } -func (ms *MerpServer) handleNewMerp() gin.HandlerFunc { +func (ms *Server) handleNewMerp() gin.HandlerFunc { return func(c *gin.Context) { // request time thing := c.Param("thing") diff --git a/server.go b/server.go index 2663dde..c4ca1d6 100644 --- a/server.go +++ b/server.go @@ -17,7 +17,7 @@ import "github.com/thoas/stats" import "github.com/astaxie/beego/orm" import _ "github.com/lib/pq" //revive:disable-line -type MerpServer struct { +type Server struct { db orm.Ormer debug bool gin *gin.Engine @@ -27,13 +27,13 @@ type MerpServer struct { thingRegex *regexp.Regexp } -func NewMerpServer() *MerpServer { - ms := new(MerpServer) +func NewServer() *Server { + ms := new(Server) ms.init() return ms } -func (ms *MerpServer) init() { +func (ms *Server) init() { ms.thingRegex = regexp.MustCompile(`^[a-zA-Z0-9\_\-]+$`) @@ -63,19 +63,19 @@ func (ms *MerpServer) init() { } } -func (ms *MerpServer) connectDB() { +func (ms *Server) connectDB() { ms.db = GetDB() } // ServeForever causes merp to serve http forever -func (ms *MerpServer) ServeForever() { +func (ms *Server) ServeForever() { err := ms.server.ListenAndServe() if err != nil { panic(err) } } -func (ms *MerpServer) HealthCheckHandler() http.HandlerFunc { +func (ms *Server) HealthCheckHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { result := gin.H{ "status": "ok", @@ -92,7 +92,7 @@ func (ms *MerpServer) HealthCheckHandler() http.HandlerFunc { } } -func (ms *MerpServer) 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() @@ -101,7 +101,7 @@ func (ms *MerpServer) StatsHandler() http.HandlerFunc { } } -func (ms *MerpServer) setupRoutes() { +func (ms *Server) setupRoutes() { if !ms.debug { gin.SetMode(gin.ReleaseMode) }