powerdns-remote-http-example/gin.go

52 lines
801 B
Go
Raw Normal View History

2024-09-14 09:12:10 +03:00
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)
setupAddrMapApi(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)
}