123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package http
- import (
- "kpt-tmr-group/dep"
- "kpt-tmr-group/http/middleware"
- "kpt-tmr-group/http/route"
- "github.com/gin-gonic/gin"
- )
- type Server struct {
- *gin.Engine
- }
- type Option func(*Server)
- func NewServer(options ...Option) *Server {
- s := &Server{
- Engine: gin.New(),
- }
- for _, option := range options {
- option(s)
- }
- return s
- }
- func ExportLogOption() Option {
- return func(s *Server) {
- s.Engine.Use(gin.LoggerWithConfig(gin.LoggerConfig{SkipPaths: []string{"/metrics", "/check"}}))
- }
- }
- func SetRouteOption() Option {
- return func(s *Server) {
- route.HTTPServerRoute()(s.Engine)
- }
- }
- func WithDependency(dep *dep.HttpDependency) Option {
- return func(s *Server) {
- s.Engine.Use(middleware.WithDependency(dep))
- }
- }
|