-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (42 loc) · 1023 Bytes
/
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
package main
import (
"context"
"app/internal"
"github.com/sohaha/zlsgo/zcli"
"github.com/sohaha/zlsgo/zlog"
"github.com/sohaha/zlsgo/zutil"
"github.com/sohaha/zlsgo/zutil/daemon"
"github.com/zlsgo/app_core/common"
"github.com/zlsgo/app_core/service"
)
func init() {
service.AppName = "ZlsApp"
zcli.Version = "0.1.0"
zcli.Name = service.AppName
zcli.EnableDetach = true
}
func main() {
if conf, err := setup(); err != nil {
if conf == nil || !conf.Base.Debug {
zcli.Error(err.Error())
} else {
zlog.Errorf("%+v\n", err)
}
}
}
func setup() (conf *service.Conf, err error) {
_ = zutil.Loadenv()
err = zutil.TryCatch(func() (err error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
di := internal.InitDI(ctx)
err = zcli.LaunchServiceRun(zcli.Name, "", func() {
conf, err = internal.Init(di, true)
common.Fatal(err)
common.Fatal(internal.Start(di))
}, &daemon.Config{Context: ctx})
_, _ = di.Invoke(internal.Stop)
return err
})
return
}