2019-10-03 19:30:04 +00:00
|
|
|
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
|
|
|
package main
|
|
|
|
|
2019-10-25 15:09:31 +00:00
|
|
|
import "fmt"
|
2019-10-25 16:17:14 +00:00
|
|
|
import "net/http"
|
2019-10-25 15:09:31 +00:00
|
|
|
import "os"
|
2019-10-25 16:17:14 +00:00
|
|
|
import "time"
|
|
|
|
|
|
|
|
//import "github.com/rs/zerolog/log"
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
import "github.com/dn365/gin-zerolog"
|
2019-10-03 19:30:04 +00:00
|
|
|
|
2019-10-25 15:09:31 +00:00
|
|
|
func serve() {
|
2019-10-25 16:17:14 +00:00
|
|
|
if os.Getenv("DEBUG") == "" {
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
}
|
|
|
|
|
|
|
|
// empty router
|
|
|
|
r := gin.New()
|
|
|
|
|
|
|
|
// wrap panics:
|
|
|
|
r.Use(gin.Recovery())
|
|
|
|
|
|
|
|
// attach logger middleware
|
|
|
|
r.Use(ginzerolog.Logger("gin"))
|
|
|
|
|
2019-10-29 16:40:30 +00:00
|
|
|
r.GET("/.well-known/healthcheck.json", func(c *gin.Context) {
|
2019-10-25 16:17:14 +00:00
|
|
|
c.JSON(200, gin.H{
|
2019-10-29 16:40:30 +00:00
|
|
|
"status": "ok",
|
|
|
|
"now": time.Now().UTC().Format(time.RFC3339),
|
2019-10-25 16:17:14 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// call it, it returns the appropriate handler function
|
|
|
|
r.GET("/merp/for/:thing", HandleNewMerp())
|
2019-10-29 16:40:30 +00:00
|
|
|
r.GET("/get/latest/merp/for/:thing", GetLatestMerp())
|
|
|
|
r.GET("/get/merps/for/:thing", GetLatestMerps())
|
2019-10-25 16:17:14 +00:00
|
|
|
|
|
|
|
port := "8080"
|
|
|
|
if os.Getenv("PORT") != "" {
|
|
|
|
port = os.Getenv("PORT")
|
2019-10-25 15:09:31 +00:00
|
|
|
}
|
2019-10-03 19:30:04 +00:00
|
|
|
|
2019-10-25 16:17:14 +00:00
|
|
|
s := &http.Server{
|
|
|
|
Addr: fmt.Sprintf(":%s", port),
|
|
|
|
Handler: r,
|
|
|
|
ReadTimeout: 10 * time.Second,
|
|
|
|
WriteTimeout: 10 * time.Second,
|
|
|
|
MaxHeaderBytes: 1 << 20,
|
2019-10-03 19:30:04 +00:00
|
|
|
}
|
2019-10-25 16:17:14 +00:00
|
|
|
s.ListenAndServe()
|
2019-10-03 19:30:04 +00:00
|
|
|
}
|