renamed type as recommended to avoid stuttering

This commit is contained in:
Jeffrey Paul 2019-11-08 21:59:16 -08:00
parent c7e2f8c4f3
commit a6d2b0ed17
3 changed files with 12 additions and 12 deletions

View File

@ -25,7 +25,7 @@ func main() {
wg.Add(1) wg.Add(1)
go func() { go func() {
ms := merp.NewMerpServer() ms := merp.NewServer()
ms.ServeForever() ms.ServeForever()
wg.Done() wg.Done()
}() }()

View File

@ -20,7 +20,7 @@ func decodeJSON(in []byte) (interface{}, error) {
return out, nil return out, nil
} }
func (ms *MerpServer) getLatestMerps() gin.HandlerFunc { func (ms *Server) getLatestMerps() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
thing := c.Param("thing") thing := c.Param("thing")
if 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) { return func(c *gin.Context) {
// request time // request time
thing := c.Param("thing") thing := c.Param("thing")

View File

@ -17,7 +17,7 @@ import "github.com/thoas/stats"
import "github.com/astaxie/beego/orm" import "github.com/astaxie/beego/orm"
import _ "github.com/lib/pq" //revive:disable-line import _ "github.com/lib/pq" //revive:disable-line
type MerpServer struct { type Server struct {
db orm.Ormer db orm.Ormer
debug bool debug bool
gin *gin.Engine gin *gin.Engine
@ -27,13 +27,13 @@ type MerpServer struct {
thingRegex *regexp.Regexp thingRegex *regexp.Regexp
} }
func NewMerpServer() *MerpServer { func NewServer() *Server {
ms := new(MerpServer) ms := new(Server)
ms.init() ms.init()
return ms return ms
} }
func (ms *MerpServer) init() { func (ms *Server) init() {
ms.thingRegex = regexp.MustCompile(`^[a-zA-Z0-9\_\-]+$`) 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() ms.db = GetDB()
} }
// ServeForever causes merp to serve http forever // ServeForever causes merp to serve http forever
func (ms *MerpServer) ServeForever() { func (ms *Server) ServeForever() {
err := ms.server.ListenAndServe() err := ms.server.ListenAndServe()
if err != nil { if err != nil {
panic(err) panic(err)
} }
} }
func (ms *MerpServer) HealthCheckHandler() http.HandlerFunc { func (ms *Server) HealthCheckHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
result := gin.H{ result := gin.H{
"status": "ok", "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) { return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
stats := ms.stats.Data() 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 { if !ms.debug {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
} }