reCoreD-UI/server/server.go
2024-04-11 11:41:33 +08:00

44 lines
745 B
Go

package server
import (
"net"
"reCoreD-UI/database"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
type Server struct {
webServer *gin.Engine
listen string
prefix string
}
func NewServer(c *cli.Context) (*Server, error) {
if err := database.Connect(c.String("mysql-dsn")); err != nil {
return nil, err
}
if c.Bool("debug") {
database.Client = database.Client.Debug()
}
return &Server{
webServer: gin.New(),
listen: net.JoinHostPort(
c.String("listen"),
c.String("port"),
),
prefix: c.String("prefix"),
}, nil
}
func (s *Server) Run() error {
logrus.Debug("server running")
defer logrus.Debug("server exit")
s.setupRoute()
return s.webServer.Run(s.listen)
}