fixed bug

This commit is contained in:
Jeffrey Paul 2019-11-08 05:01:57 -08:00
parent 62e7600a22
commit 6c9b82a10c
3 changed files with 16 additions and 5 deletions

View File

@ -1,6 +1,7 @@
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
package merp
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
const basePage = `<!DOCTYPE html>
<html>
<head>

13
merp.go
View File

@ -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

View File

@ -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