From 6c9b82a10c2f45ac4d5f5fc10c63067ded34f00a Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Fri, 8 Nov 2019 05:01:57 -0800 Subject: [PATCH] fixed bug --- indexpage.go | 3 ++- merp.go | 13 ++++++++++--- server.go | 5 ++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/indexpage.go b/indexpage.go index 78e3af9..c5e67ca 100644 --- a/indexpage.go +++ b/indexpage.go @@ -1,6 +1,7 @@ -//3456789112345676892123456789312345678941234567895123456789612345678971234567898 package merp +//3456789112345676892123456789312345678941234567895123456789612345678971234567898 + const basePage = ` diff --git a/merp.go b/merp.go index f7c54d2..5b619c0 100644 --- a/merp.go +++ b/merp.go @@ -5,6 +5,7 @@ import "net/http" import "regexp" import "time" +import "github.com/astaxie/beego/orm" import "github.com/gin-gonic/gin" import "github.com/google/uuid" import "github.com/rs/zerolog/log" @@ -30,10 +31,12 @@ func decodeJSON(in []byte) interface{} { func getLatestMerps() gin.HandlerFunc { ThingRegex := thingRegex() - orm := models.GetOrmObject() + o := models.GetOrmObject() h := func(c *gin.Context) { + thing := c.Param("thing") + if thing != "" { if ThingRegex.MatchString(thing) == false { c.JSON(http.StatusPreconditionFailed, gin.H{ @@ -43,9 +46,13 @@ func getLatestMerps() gin.HandlerFunc { }) return } - qs := orm.QueryTable("merp").Filter("thing", thing).OrderBy("-created").Limit(50) + } + + var qs orm.QuerySeter + if thing == "" { + qs = o.QueryTable("merp").OrderBy("-created").Limit(50) } else { - qs := orm.QueryTable("merp").OrderBy("-created").Limit(50) + qs = o.QueryTable("merp").Filter("thing", thing).OrderBy("-created").Limit(50) } var merps []*models.Merp diff --git a/server.go b/server.go index 6aad5f5..6819649 100644 --- a/server.go +++ b/server.go @@ -1,6 +1,7 @@ -//3456789112345676892123456789312345678941234567895123456789612345678971234567898 package merp +//3456789112345676892123456789312345678941234567895123456789612345678971234567898 + import "encoding/json" import "fmt" import "net/http" @@ -14,6 +15,7 @@ import "github.com/gin-gonic/gin" import "github.com/dn365/gin-zerolog" import "github.com/thoas/stats" +// ServeForever causes merp to serve http forever func ServeForever() { s := getServer() s.ListenAndServe() @@ -73,6 +75,7 @@ func getRouter() *gin.Engine { r.GET("/.well-known/healthcheck.json", gin.WrapF(getHealthCheckHandler())) r.GET("/admin/healthcheck.json", gin.WrapF(getHealthCheckHandler())) r.GET("/admin/stats.json", gin.WrapF(getStatsHandler(statsMiddleware))) + r.GET("/admin/other.json", gin.WrapF(getStatsHandler(statsMiddleware))) // call it, it returns the appropriate handler function // so we can execute some code at startup time