From 62e7600a227bc826c7c164dd736db07640199a11 Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Fri, 8 Nov 2019 04:55:54 -0800 Subject: [PATCH] allow fetching merps of all types now --- merp.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/merp.go b/merp.go index 44048fa..f7c54d2 100644 --- a/merp.go +++ b/merp.go @@ -34,17 +34,21 @@ func getLatestMerps() gin.HandlerFunc { h := func(c *gin.Context) { thing := c.Param("thing") - if ThingRegex.MatchString(thing) == false { - c.JSON(http.StatusPreconditionFailed, gin.H{ - "this": "failed", - "status": http.StatusPreconditionFailed, - "because": "invalid thing format, try [a-zA-Z0-9-_]", - }) - return + if thing != "" { + if ThingRegex.MatchString(thing) == false { + c.JSON(http.StatusPreconditionFailed, gin.H{ + "this": "failed", + "status": http.StatusPreconditionFailed, + "because": "invalid thing format, try [a-zA-Z0-9-_]", + }) + return + } + qs := orm.QueryTable("merp").Filter("thing", thing).OrderBy("-created").Limit(50) + } else { + qs := orm.QueryTable("merp").OrderBy("-created").Limit(50) } var merps []*models.Merp - qs := orm.QueryTable("merp").Filter("thing", thing).OrderBy("-created").Limit(50) qs.All(&merps) output := make([]map[string]interface{}, 0)