-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
72 lines (57 loc) · 1.64 KB
/
service.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/Sirupsen/logrus"
"github.com/molecul/qa_portal/checker"
"github.com/molecul/qa_portal/model"
"github.com/molecul/qa_portal/util/database"
"github.com/molecul/qa_portal/web"
"gopkg.in/yaml.v2"
)
const TimestampFormat = "06-01-02 15:04:05.000"
type PrettyFormatter struct{}
func (f *PrettyFormatter) Format(entry *logrus.Entry) ([]byte, error) {
return []byte(fmt.Sprintf("%s|%7s|%s\n", entry.Time.Format(TimestampFormat), entry.Level.String(), entry.Message)), nil
}
type Configuration struct {
Web *web.Configuration
Model *model.Configuration
Checker *checker.Configuration
Database *database.Configuration
}
func init() {
logrus.SetFormatter(&PrettyFormatter{})
// Output to stdout instead of the default stderr
logrus.SetOutput(os.Stdout)
logrus.SetLevel(logrus.DebugLevel)
}
func Start(c *Configuration) {
logrus.Infof("Starting server")
if err := database.Init(c.Database); err != nil {
logrus.Fatalf("Error when connecting to db: %v", err)
}
if err := model.Init(c.Model); err != nil {
logrus.Fatalf("Error syncing db: %v", err)
}
if err := checker.Init(c.Checker); err != nil {
logrus.Fatalf("Error when creating checker: %v", err)
}
web.Run(c.Web)
}
func main() {
var confPath string
flag.StringVar(&confPath, "config", "config.yml", "path to config yaml file")
flag.Parse()
cfgRaw, err := ioutil.ReadFile(confPath)
if err != nil {
logrus.Fatalf("Cannot open config file %s: %v", confPath, err)
}
cfg := new(Configuration)
if err := yaml.Unmarshal(cfgRaw, cfg); err != nil {
logrus.Fatalf("Cannot unmarshal config: %v", err)
}
Start(cfg)
}