sk-matrix-project/backend/golang/matrix-middle-service/cmd/service/main.go

39 lines
884 B
Go
Raw Normal View History

package service
import (
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
2023-03-24 11:34:13 +08:00
"matrix-common/constants"
2023-03-24 11:46:51 +08:00
"matrix-common/pkg/logger"
_ "matrix-middle-service/docs"
"matrix-middle-service/internel/app"
"matrix-middle-service/pkg/config/toml"
)
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)
}
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
_ = toml.GenerateConfig()
logger.Log().Fatalf("未找到配置文件, 已生成示例配置文件于运行路径下")
} else {
logger.Log().Fatalf("配置解析失败 %s", err)
}
}
viper.OnConfigChange(func(in fsnotify.Event) {
logger.Log().Info(in.Name)
app.Run()
})
viper.WatchConfig()
app.Run()
2023-02-26 21:34:53 +08:00
defer app.Shutdown()
}