sk-matrix-project/backend/golang/matrix-middle-service/cmd/service/main.go
Shikong c5c3633ac4 添加 数据源配置
数据源初始化
多数据源初步支持
2023-02-26 21:10:43 +08:00

45 lines
990 B
Go

package service
import (
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"matrix-middle-service/constants"
_ "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() {
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()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
app.Shutdown()
}