feat: add middlewares

This commit is contained in:
Rogee
2024-12-06 17:15:28 +08:00
parent 29894cff9c
commit 869625d70a
10 changed files with 169 additions and 125 deletions

View File

@@ -9,7 +9,7 @@ const DefaultPrefix = "Http"
type Config struct {
StaticPath *string
StaticRoute *string
Host *string
BaseURI *string
Port uint
Tls *Tls
Cors *Cors
@@ -34,12 +34,5 @@ type Whitelist struct {
}
func (h *Config) Address() string {
if h.Host == nil {
return h.PortString()
}
return fmt.Sprintf("%s:%d", *h.Host, h.Port)
}
func (h *Config) PortString() string {
return fmt.Sprintf(":%d", h.Port)
}

View File

@@ -38,6 +38,7 @@ func (svc *Service) Serve() error {
OnShutdownError: func(err error) {
log.Error("http server shutdown error: ", err)
},
// DisableStartupMessage: true,
}
@@ -52,7 +53,7 @@ func (svc *Service) Serve() error {
svc.Engine.Shutdown()
})
return svc.Engine.Listen(svc.conf.PortString(), listenConfig)
return svc.Engine.Listen(svc.conf.Address(), listenConfig)
}
func Provide(opts ...opt.Option) error {