-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
72 lines (56 loc) · 1.46 KB
/
main.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
/*
Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved
*/
package main
import (
"flag"
"fmt"
"os"
"github.com/sirupsen/logrus"
"github.com/opensourceways/message-manager/common/postgresql"
"github.com/opensourceways/message-manager/common/user"
"github.com/opensourceways/message-manager/config"
"github.com/opensourceways/message-manager/server"
)
func gatherOptions(fs *flag.FlagSet, args ...string) (Options, error) {
var o Options
o.AddFlags(fs)
err := fs.Parse(args)
return o, err
}
type Options struct {
Config string
}
func (o *Options) AddFlags(fs *flag.FlagSet) {
fs.StringVar(&o.Config, "config-file", "", "Path to config file.")
}
// @title Message Manager
// @version 1.0
// @description This is a Message Manager Server.
func main() {
o, err := gatherOptions(
flag.NewFlagSet(os.Args[0], flag.ExitOnError),
os.Args[1:]...,
)
if err != nil {
logrus.Fatalf("new Options failed, err:%s", err.Error())
return
}
// cfg
cfg := new(config.Config)
if err = config.LoadConfig(o.Config, cfg); err != nil {
logrus.Errorf("load config, err:%s", err.Error())
return
}
// init postgresql
if err := postgresql.Init(&cfg.Postgresql); err != nil {
fmt.Println("Postgresql数据库初始化失败, err:", err)
return
}
//if err := cassandra.Init(&cfg.Cassandra); err != nil {
// fmt.Println("Cassandra数据库初始化失败")
//}
// init user
user.Init(&cfg.User)
server.StartWebServer()
}