2023-02-26 02:50:56 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/fsnotify/fsnotify"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
"github.com/spf13/viper"
|
2023-02-26 03:20:21 +08:00
|
|
|
"matrix-middle-service/constants"
|
2023-02-26 02:50:56 +08:00
|
|
|
_ "matrix-middle-service/docs"
|
|
|
|
"matrix-middle-service/internel/app"
|
|
|
|
"matrix-middle-service/pkg/config/toml"
|
|
|
|
"matrix-middle-service/pkg/logger"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Main() {
|
2023-02-26 03:20:21 +08:00
|
|
|
viper.SetConfigName(constants.ConfigFileName)
|
|
|
|
viper.SetConfigType(constants.ConfigType)
|
|
|
|
for _, path := range constants.ConfigPaths {
|
|
|
|
viper.AddConfigPath(path)
|
|
|
|
}
|
2023-02-26 02:50:56 +08:00
|
|
|
|
|
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
|
|
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
|
|
|
_ = toml.GenerateConfig()
|
|
|
|
logger.Log().Fatalf("未找到配置文件, 已生成示例配置文件于运行路径下")
|
|
|
|
} else {
|
|
|
|
logger.Log().Fatalf("配置解析失败 %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
viper.WatchConfig()
|
|
|
|
viper.OnConfigChange(func(in fsnotify.Event) {
|
|
|
|
logger.Log().Info(in.Name)
|
|
|
|
app.Run()
|
|
|
|
})
|
|
|
|
app.Run()
|
|
|
|
|
|
|
|
quit := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(quit, os.Interrupt)
|
|
|
|
<-quit
|
|
|
|
app.Shutdown()
|
|
|
|
}
|