-
Notifications
You must be signed in to change notification settings - Fork 17
/
main_init.go
129 lines (105 loc) · 2.42 KB
/
main_init.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"flag"
"strings"
"github.com/Ptt-official-app/go-pttbbsweb/boardd"
"github.com/Ptt-official-app/go-pttbbsweb/db"
"github.com/Ptt-official-app/go-pttbbsweb/dbcs"
"github.com/Ptt-official-app/go-pttbbsweb/mand"
"github.com/Ptt-official-app/go-pttbbsweb/queue"
"github.com/Ptt-official-app/go-pttbbsweb/schema"
"github.com/Ptt-official-app/go-pttbbsweb/types"
"github.com/spf13/viper"
pttbbsapi "github.com/Ptt-official-app/go-pttbbs/api"
"github.com/Ptt-official-app/go-pttbbs/ptttype"
pttbbstypes "github.com/Ptt-official-app/go-pttbbs/types"
"github.com/sirupsen/logrus"
jww "github.com/spf13/jwalterweatherman"
)
// Params
//
// filename: ini filename
//
// Return
//
// error: err
func initAllConfig(filename string) error {
filenameList := strings.Split(filename, ".")
if len(filenameList) == 1 {
return ErrInvalidIni
}
filenamePrefix := strings.Join(filenameList[:len(filenameList)-1], ".")
filenamePostfix := filenameList[len(filenameList)-1]
viper.SetConfigName(filenamePrefix)
viper.SetConfigType(filenamePostfix)
viper.AddConfigPath("/etc/go-pttbbsweb")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
return err
}
logrus.Debugf("viper keys: %v", viper.AllKeys())
err = types.InitConfig()
if err != nil {
return err
}
err = db.InitConfig()
if err != nil {
return err
}
err = schema.InitConfig()
if err != nil {
return err
}
err = pttbbsapi.InitConfig()
if err != nil {
return err
}
err = pttbbstypes.InitConfig()
if err != nil {
return err
}
err = queue.InitConfig()
if err != nil {
return err
}
err = boardd.InitConfig()
if err != nil {
return err
}
err = mand.InitConfig()
if err != nil {
return err
}
err = dbcs.InitConfig()
if err != nil {
return err
}
return nil
}
func initMain() error {
jww.SetLogThreshold(jww.LevelDebug)
jww.SetStdoutThreshold(jww.LevelDebug)
logrus.SetLevel(logrus.InfoLevel)
filename := ""
flag.StringVar(&filename, "ini", "config.ini", "ini filename")
flag.Parse()
err := initAllConfig(filename)
if err != nil {
return err
}
err = schema.Init()
if err != nil {
return err
}
err = boardd.Init(false)
if err != nil {
return err
}
err = mand.Init(false)
if err != nil {
return err
}
logrus.Infof("initMain: done: MAX_USERS: %v MAX_ACTIVE: %v MAX_BOARD: %v HOTBOARDCACHE: %v", ptttype.MAX_USERS, ptttype.MAX_ACTIVE, ptttype.MAX_BOARD, ptttype.HOTBOARDCACHE)
return nil
}