reCoreD-UI/server/server.go

41 lines
676 B
Go
Raw Normal View History

2024-04-03 09:05:12 +00:00
package server
import (
"net"
2024-04-09 08:28:18 +00:00
"reCoreD-UI/database"
2024-04-03 09:05:12 +00:00
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
type Server struct {
2024-04-09 08:28:18 +00:00
webServer *gin.Engine
listen string
prefix string
2024-04-03 09:05:12 +00:00
}
func NewServer(c *cli.Context) (*Server, error) {
2024-04-09 08:28:18 +00:00
if err := database.Connect(c.String("mysql-dsn")); err != nil {
2024-04-03 09:05:12 +00:00
return nil, err
}
return &Server{
2024-04-09 08:28:18 +00:00
webServer: gin.New(),
2024-04-03 09:05:12 +00:00
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)
}