@@ -6,12 +6,11 @@ import (
66 "fmt"
77 "log"
88 "os"
9- "os/signal"
109 "sync"
11- "syscall"
1210 "time"
1311
1412 "github.com/wetor/AnimeGo/assets"
13+ "github.com/wetor/AnimeGo/cmd/common"
1514 "github.com/wetor/AnimeGo/configs"
1615 _ "github.com/wetor/AnimeGo/docs"
1716 "github.com/wetor/AnimeGo/internal/animego/anidata"
@@ -45,11 +44,6 @@ const (
4544 DefaultConfigFile = "data/animego.yaml"
4645)
4746
48- var (
49- version = "dev"
50- buildTime = "dev"
51- )
52-
5347var (
5448 ctx , cancel = context .WithCancel (context .Background ())
5549 configFile string
@@ -60,36 +54,25 @@ var (
6054 BangumiCacheMutex sync.Mutex
6155)
6256
63- func init () {
64- var err error
65- err = os .Setenv ("ANIMEGO_VERSION" , fmt .Sprintf ("%s-%s" , version , buildTime ))
66- if err != nil {
67- panic (err )
68- }
69- }
70-
7157func main () {
72- printInfo ()
58+ common . PrintInfo ()
7359
7460 flag .StringVar (& configFile , "config" , DefaultConfigFile , "配置文件路径;配置文件中的相对路径均是相对与程序的位置" )
7561 flag .BoolVar (& debug , "debug" , false , "Debug模式,将会显示更多的日志" )
7662 flag .BoolVar (& webapi , "web" , true , "启用Web API,默认启用" )
7763 flag .Parse ()
7864
79- sigs := make (chan os.Signal , 1 )
80- signal .Notify (sigs , syscall .SIGINT , syscall .SIGTERM , syscall .SIGHUP , syscall .SIGQUIT )
65+ common .RegisterExit (doExit )
66+ Main ()
67+ }
68+
69+ func doExit () {
70+ pkgLog .Infof ("正在退出..." )
71+ cancel ()
8172 go func () {
82- for s := range sigs {
83- switch s {
84- case syscall .SIGINT , syscall .SIGTERM , syscall .SIGHUP , syscall .SIGQUIT :
85- pkgLog .Infof ("收到退出信号: %v" , s )
86- doExit ()
87- default :
88- pkgLog .Infof ("收到其他信号: %v" , s )
89- }
90- }
73+ time .Sleep (5 * time .Second )
74+ os .Exit (0 )
9175 }()
92- Main (ctx )
9376}
9477
9578func InitDefaultConfig () {
@@ -126,30 +109,7 @@ func InitDefaultAssets(dataPath string, skip bool) {
126109 assets .WritePlugins (assets .Dir , xpath .Join (dataPath , assets .Dir ), skip )
127110}
128111
129- func doExit () {
130- pkgLog .Infof ("正在退出..." )
131- cancel ()
132- go func () {
133- time .Sleep (5 * time .Second )
134- os .Exit (0 )
135- }()
136- }
137-
138- func printInfo () {
139- fmt .Println (`--------------------------------------------------
140- ___ _ ______
141- / | ____ (_)____ ___ ___ / ____/____
142- / /| | / __ \ / // __ \__ \ / _ \ / / __ / __ \
143- / ___ | / / / // // / / / / // __// /_/ // /_/ /
144- /_/ |_|/_/ /_//_//_/ /_/ /_/ \___/ \____/ \____/
145- ` )
146- fmt .Printf ("AnimeGo %s\n " , os .Getenv ("ANIMEGO_VERSION" ))
147- fmt .Printf ("AnimeGo config v%s\n " , configs .ConfigVersion )
148- fmt .Printf ("%s\n " , constant .AnimeGoGithub )
149- fmt .Println ("--------------------------------------------------" )
150- }
151-
152- func Main (ctx context.Context ) {
112+ func Main () {
153113 configFile = xpath .Abs (configFile )
154114 // 初始化默认配置、升级配置
155115 InitDefaultConfig ()
@@ -184,7 +144,8 @@ func Main(ctx context.Context) {
184144
185145 // 初始化插件-gpython
186146 plugin .Init (& plugin.Options {
187- Path : constant .PluginPath ,
147+ Path : constant .PluginPath ,
148+ Debug : debug ,
188149 })
189150 // 载入AnimeGo数据库(缓存)
190151 bolt := cache .NewBolt ()
0 commit comments