route update
This commit is contained in:
parent
5a266e9e6c
commit
a67b2d7724
@ -9,14 +9,19 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
apiPrefix = "/api"
|
||||||
|
metricPrefix = "/metrics"
|
||||||
|
)
|
||||||
|
|
||||||
func (s *Server) setupRoute() {
|
func (s *Server) setupRoute() {
|
||||||
username, password, err := s.controller.GetAdmin()
|
username, password, err := s.controller.GetAdmin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
server := s.webServer.Group(s.prefix)
|
metricHandler := gin.New()
|
||||||
server.Group("/metrics", func(ctx *gin.Context) {
|
metricHandler.GET(metricPrefix, func(ctx *gin.Context) {
|
||||||
if err := s.controller.RefreshMetrics(); err != nil {
|
if err := s.controller.RefreshMetrics(); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
@ -25,7 +30,7 @@ func (s *Server) setupRoute() {
|
|||||||
|
|
||||||
apiHandler := gin.New()
|
apiHandler := gin.New()
|
||||||
|
|
||||||
groupV1 := apiHandler.Group("/api", gin.BasicAuth(gin.Accounts{
|
groupV1 := apiHandler.Group(apiPrefix, gin.BasicAuth(gin.Accounts{
|
||||||
username: password,
|
username: password,
|
||||||
})).Group("/v1")
|
})).Group("/v1")
|
||||||
|
|
||||||
@ -44,13 +49,16 @@ func (s *Server) setupRoute() {
|
|||||||
PUT("/:domain", s.updateRecord).
|
PUT("/:domain", s.updateRecord).
|
||||||
DELETE("/:domain/:id", s.deleteRecord)
|
DELETE("/:domain/:id", s.deleteRecord)
|
||||||
|
|
||||||
|
server := s.webServer.Group(s.prefix)
|
||||||
server.Use(func(ctx *gin.Context) {
|
server.Use(func(ctx *gin.Context) {
|
||||||
uri := ctx.Request.RequestURI
|
uri := ctx.Request.RequestURI
|
||||||
logrus.Debug(uri)
|
logrus.Debug(uri)
|
||||||
|
switch {
|
||||||
if strings.HasPrefix(uri, path.Join(s.prefix, uri)) {
|
case strings.HasPrefix(uri, path.Join(s.prefix, apiPrefix)):
|
||||||
apiHandler.HandleContext(ctx)
|
apiHandler.HandleContext(ctx)
|
||||||
} else {
|
case strings.HasPrefix(uri, path.Join(s.prefix, metricPrefix)):
|
||||||
|
metricHandler.HandleContext(ctx)
|
||||||
|
default:
|
||||||
staticFileHandler()(ctx)
|
staticFileHandler()(ctx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user