李伟乐 2 years ago
parent 029cde0c91
commit b731d13a88
  1. 25
      xserver/http.go

@ -7,29 +7,30 @@ import (
"time" "time"
) )
type httpServer struct { type Http struct {
server *http.Server server *http.Server
} }
func (h *httpServer) Start() error { func (h *Http) Start() error {
return h.server.ListenAndServe() return h.server.ListenAndServe()
} }
func (h *httpServer) Shutdown(ctx context.Context) error { func (h *Http) Shutdown(ctx context.Context) error {
return h.server.Shutdown(ctx) return h.server.Shutdown(ctx)
} }
func NewHttp(httpHost string, app *gin.Engine) *httpServer { func NewHttp(httpHost string, app *gin.Engine) *Http {
server := &http.Server{ return &Http{
Addr: httpHost, server: &http.Server{
Handler: app, Addr: httpHost,
ReadTimeout: 60 * time.Second, Handler: app,
WriteTimeout: 60 * time.Second, ReadTimeout: 60 * time.Second,
MaxHeaderBytes: 20 << 20, WriteTimeout: 60 * time.Second,
MaxHeaderBytes: 20 << 20,
},
} }
return &httpServer{server: server}
} }
func (c *httpServer) Name() string { func (c *Http) Name() string {
return "http" return "http"
} }

Loading…
Cancel
Save