reCoreD-UI/server/route.go
Sense T 8a8ea59b71 1
2024-04-03 17:05:12 +08:00

46 lines
841 B
Go

package server
import (
"path"
"strings"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
func (s *Server) setupRoute() {
username, password, err := s.controller.GetAdmin()
if err != nil {
logrus.Fatal(err)
}
server := s.webServer.Group(s.prefix, gin.BasicAuth(gin.Accounts{
username: password,
}))
apiHandler := gin.New()
groupV1 := apiHandler.Group("/api/v1")
domains := groupV1.Group("/domains")
domains.
GET("/", s.getDomains).
POST("/", s.createDomain).
PUT("/", s.updateDomain).
DELETE("/:id", s.deleteDomain)
records := groupV1.Group("/records")
records.
GET("/")
server.Use(func(ctx *gin.Context) {
uri := ctx.Request.RequestURI
logrus.Debug(uri)
if strings.HasPrefix(uri, path.Join(s.prefix, uri)) {
apiHandler.HandleContext(ctx)
} else {
// TODO: Static Page
}
})
}