51 lines
781 B
Go
51 lines
781 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"os"
|
||
|
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
func setupGin() *gin.Engine {
|
||
|
if os.Getenv("GIN_MODE") == "" {
|
||
|
gin.SetMode(gin.ReleaseMode)
|
||
|
}
|
||
|
|
||
|
r := ginNewEngine()
|
||
|
r.GET("/health", func(c *gin.Context) {
|
||
|
c.JSON(http.StatusOK, gin.H{"status": "UP"})
|
||
|
})
|
||
|
setupDnsApi(r)
|
||
|
setupPrometheus(r)
|
||
|
return r
|
||
|
}
|
||
|
|
||
|
func ginNewEngine() *gin.Engine {
|
||
|
var r *gin.Engine
|
||
|
|
||
|
switch gin.Mode() {
|
||
|
case gin.ReleaseMode:
|
||
|
r = gin.New()
|
||
|
ginCustomLogger(r)
|
||
|
default:
|
||
|
r = gin.Default()
|
||
|
}
|
||
|
|
||
|
r.Use(ginSetServerHeader)
|
||
|
return r
|
||
|
}
|
||
|
|
||
|
func ginCustomLogger(r *gin.Engine) {
|
||
|
r.Use(gin.LoggerWithConfig(gin.LoggerConfig{
|
||
|
SkipPaths: []string{
|
||
|
"/health",
|
||
|
"/metrics/",
|
||
|
},
|
||
|
}))
|
||
|
}
|
||
|
|
||
|
func ginSetServerHeader(c *gin.Context) {
|
||
|
c.Writer.Header().Set("Server", userAgent)
|
||
|
}
|