53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
|
package main
|
|
|
|
import "fmt"
|
|
import "net/http"
|
|
import "os"
|
|
import "time"
|
|
|
|
//import "github.com/rs/zerolog/log"
|
|
import "github.com/gin-gonic/gin"
|
|
import "github.com/dn365/gin-zerolog"
|
|
|
|
func serve() {
|
|
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"))
|
|
|
|
r.GET("/.well-known/healthcheck.json", func(c *gin.Context) {
|
|
c.JSON(200, gin.H{
|
|
"status": "ok",
|
|
"now": time.Now().UTC().Format(time.RFC3339),
|
|
})
|
|
})
|
|
|
|
// call it, it returns the appropriate handler function
|
|
r.GET("/merp/for/:thing", HandleNewMerp())
|
|
r.GET("/get/latest/merp/for/:thing", GetLatestMerp())
|
|
r.GET("/get/merps/for/:thing", GetLatestMerps())
|
|
|
|
port := "8080"
|
|
if os.Getenv("PORT") != "" {
|
|
port = os.Getenv("PORT")
|
|
}
|
|
|
|
s := &http.Server{
|
|
Addr: fmt.Sprintf(":%s", port),
|
|
Handler: r,
|
|
ReadTimeout: 10 * time.Second,
|
|
WriteTimeout: 10 * time.Second,
|
|
MaxHeaderBytes: 1 << 20,
|
|
}
|
|
s.ListenAndServe()
|
|
}
|