40 lines
873 B
Go
40 lines
873 B
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/fsnotify/fsnotify"
|
|
"github.com/spf13/viper"
|
|
"iptables-helper/internel/app"
|
|
"iptables-helper/pkg/config/toml"
|
|
"iptables-helper/pkg/constants"
|
|
"iptables-helper/pkg/logger"
|
|
|
|
_ "iptables-helper/docs"
|
|
)
|
|
|
|
func Main() {
|
|
viper.SetConfigName(constants.ConfigFileName)
|
|
viper.SetConfigType(constants.ConfigType)
|
|
for _, path := range constants.ConfigPaths {
|
|
viper.AddConfigPath(path)
|
|
}
|
|
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
var configFileNotFoundError viper.ConfigFileNotFoundError
|
|
if errors.As(err, &configFileNotFoundError) {
|
|
_ = toml.GenerateConfig()
|
|
logger.Log().Fatalf("未找到配置文件, 已生成示例配置文件于运行路径下")
|
|
}
|
|
}
|
|
|
|
viper.OnConfigChange(func(in fsnotify.Event) {
|
|
logger.Log().Info(in.Name)
|
|
app.Run()
|
|
})
|
|
viper.WatchConfig()
|
|
|
|
app.Run()
|
|
|
|
defer app.Shutdown()
|
|
}
|