将 web 框架从 gin 切换到 fiber
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"proxy-server/server/pkg/env"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
http *http.Server
|
||||
web *fiber.App
|
||||
}
|
||||
|
||||
func New() *Server {
|
||||
@@ -18,15 +16,14 @@ func New() *Server {
|
||||
}
|
||||
|
||||
func (s *Server) Run() error {
|
||||
address := ":" + strconv.Itoa(int(env.AppWebPort))
|
||||
engine := gin.Default()
|
||||
s.http = &http.Server{Addr: address, Handler: engine}
|
||||
s.web = fiber.New()
|
||||
|
||||
// 配置中间件和路由
|
||||
Router(engine)
|
||||
Router(s.web)
|
||||
|
||||
// 启动服务
|
||||
err := s.http.ListenAndServe()
|
||||
address := ":" + strconv.Itoa(int(env.AppWebPort))
|
||||
err := s.web.Listen(address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -35,7 +32,7 @@ func (s *Server) Run() error {
|
||||
}
|
||||
|
||||
func (s *Server) Stop() error {
|
||||
err := s.http.Shutdown(context.Background())
|
||||
err := s.web.Shutdown()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user