merp/merp.go

55 lines
1.1 KiB
Go
Raw Normal View History

2019-10-25 16:17:14 +00:00
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
package main
import "net/http"
import "regexp"
import "time"
import "github.com/rs/zerolog/log"
import "github.com/gin-gonic/gin"
2019-10-25 16:25:17 +00:00
/*
2019-10-25 16:17:14 +00:00
func GetLatestMerps() gin.HandlerFunc {
}
func GetLatestMerp() gin.HandlerFunc {
}
2019-10-25 16:25:17 +00:00
*/
2019-10-25 16:17:14 +00:00
func HandleNewMerp() gin.HandlerFunc {
THING_REGEX, e := regexp.Compile(`^[a-zA-Z0-9\_\-]+$`)
if e != nil {
panic(e)
}
h := func(c *gin.Context) {
thing := c.Param("thing")
if THING_REGEX.MatchString(thing) == false {
log.Info().Msgf("%s didnt match", thing)
c.JSON(http.StatusPreconditionFailed, gin.H{
"this": "failed",
})
return
}
log.Info().Msgf("%s matched", thing)
//web.Get(`/merp/for/([A-Za-z0-9\-\_\.]+)`, merpHandler)
content := gin.H{}
for k, v := range c.Request.URL.Query() {
content[k] = v[0]
}
c.JSON(http.StatusOK, gin.H{
"this": "succeeded",
"by": "merping",
"the": "merp",
"with": gin.H{
"thing": thing,
"created": time.Now().UTC().Format(time.RFC3339),
"content": content,
},
})
}
return h
}