/
run.go
48 lines (35 loc) · 969 Bytes
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"flag"
"github.com/AnthonyCapirchio/golem/internal/config"
"github.com/AnthonyCapirchio/golem/internal/server"
"github.com/AnthonyCapirchio/golem/internal/services"
log "github.com/sirupsen/logrus"
)
type runOpts struct {
configFile string
}
func runCmd() command {
fs := flag.NewFlagSet("golem run", flag.ExitOnError)
opts := &runOpts{}
fs.StringVar(&opts.configFile, "config", ConfigPath, "Config File")
return command{fs, func(args []string) error {
fs.Parse(args)
return run(opts)
}}
}
func run(opts *runOpts) (err error) {
log.Info("Load configuration file")
cfg := config.LoadConfig(opts.configFile)
log.Info("Initialize new default server. ", cfg.Port)
defaultServer := server.NewServer(cfg.Port)
for _, service := range cfg.Services {
func(service config.Service) {
services.Launch(defaultServer, cfg.Vars, service)
}(service)
}
if defaultServer != nil {
defaultServer.Listen()
}
return nil
}