debug needed

This commit is contained in:
Sense T
2022-09-26 03:04:07 +00:00
parent 0ce8374276
commit 4c80f8a25e
39 changed files with 8233 additions and 0 deletions

74
cmd/config/config.go Normal file
View File

@@ -0,0 +1,74 @@
package config
import (
"os"
"git.sense-t.eu.org/ACE/ace/servers/qemuserver"
"git.sense-t.eu.org/ACE/ace/servers/webserver"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v3"
)
var Command *cli.Command
type Config struct {
Debug bool `yaml:"debug"`
WEBServer *webserver.Options `yaml:"webserver"`
Qemu *qemuserver.Options `yaml:"qemu"`
}
func init() {
Command = &cli.Command{
Name: "config",
Usage: "config file options",
Aliases: []string{"conf", "cfg"},
Subcommands: []*cli.Command{
{
Name: "generate",
Usage: "generate config file",
Action: genconf,
Aliases: []string{"gen"},
},
{
Name: "check",
Usage: "check config file",
Action: checkconf,
},
},
}
}
func NewConfig() *Config {
return &Config{
Debug: true,
WEBServer: webserver.ExampleOptions(),
Qemu: qemuserver.ExampleOptions(),
}
}
func genconf(c *cli.Context) error {
f, err := os.OpenFile(c.String("config"), os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer f.Close()
return yaml.NewEncoder(f).Encode(NewConfig())
}
func checkconf(c *cli.Context) error {
_, err := ReadConfig(c)
return err
}
func ReadConfig(c *cli.Context) (*Config, error) {
f, err := os.OpenFile(c.String("config"), os.O_RDONLY, 0644)
if err != nil {
return nil, err
}
defer f.Close()
config := &Config{}
err = yaml.NewDecoder(f).Decode(config)
return config, err
}

58
cmd/server/server.go Normal file
View File

@@ -0,0 +1,58 @@
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)
}
qemuserver.Setup(s.options.Qemu)
webserver.Setup(s.options.WEBServer)
<-make(chan int)
return nil
}
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()
}