-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
60 lines (51 loc) · 945 Bytes
/
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
package lama
import (
gookit "github.com/gookit/config/v2"
"github.com/gookit/config/v2/toml"
"github.com/kataras/golog"
"log"
"os"
"path/filepath"
)
func init() {
newCfg()
newLog()
}
type Log = *golog.Logger
type Cfg = *gookit.Config
var Conf Cfg
var Print Log
type provide struct {
}
func (s *provide) Provide() (Cfg, Log) {
return Conf, Print
}
func newLog() Log {
if Print == nil {
Print = golog.Default
level := "debug"
if Conf != nil {
level = Conf.String("app.logLevel", "debug")
}
Print.SetLevel(level)
}
return Print
}
func newCfg() Cfg {
if Conf == nil {
gookit.AddDriver(toml.Driver)
Conf = gookit.Default()
Conf.WithOptions(func(opt *gookit.Options) {
opt.DecoderConfig.TagName = "json"
})
Conf.LoadFiles(GetWorkerDir() + "/cfg.json")
}
return Conf
}
func GetWorkerDir() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
return dir
}