ace/cmd/server/server.go

73 lines
1.3 KiB
Go
Raw Normal View History

2022-09-26 03:04:07 +00:00
package server
import (
"git.sense-t.eu.org/ACE/ace/cmd/config"
"git.sense-t.eu.org/ACE/ace/servers/qemuserver"
"git.sense-t.eu.org/ACE/ace/servers/webserver"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
type Server struct {
options *config.Config
}
var Command *cli.Command
func init() {
Command = &cli.Command{
Name: "server",
Usage: "run ace server",
Action: runServer,
}
}
func NewServer(c *config.Config) (*Server, error) {
return &Server{
options: c,
}, nil
}
func (s *Server) Run() error {
if s.options.Debug {
gin.SetMode(gin.DebugMode)
logrus.SetLevel(logrus.DebugLevel)
} else {
logrus.SetLevel(logrus.InfoLevel)
gin.SetMode(gin.ReleaseMode)
}
2022-09-27 02:21:06 +00:00
qemu, err := qemuserver.NewServer(s.options.Qemu)
if err != nil {
2022-09-26 08:07:25 +00:00
return err
}
webServer, err := webserver.NewServer(s.options.WEBServer)
if err != nil {
return err
}
2022-09-27 02:21:06 +00:00
webServer.RTCConnector.QEMU = qemu
go func() {
if err := qemu.Run(); err != nil {
logrus.Fatal("cannot run qemuserver with error: ", err)
}
}()
2022-09-26 08:07:25 +00:00
return webServer.Run()
2022-09-26 03:04:07 +00:00
}
func runServer(c *cli.Context) error {
config, err := config.ReadConfig(c)
if err != nil {
return err
}
server, err := NewServer(config)
if err != nil {
return err
}
return server.Run()
}