package main import ( "github.com/fsnotify/fsnotify" "github.com/spf13/viper" "gofiber.study.skcks.cn/app" "gofiber.study.skcks.cn/common/logger" "os" "os/signal" _ "github.com/go-sql-driver/mysql" _ "gofiber.study.skcks.cn/docs" ) // @title GoFiber Study API // @version 1.0 // @description 基于 Fiber 框架的 swagger // @termsOfService http://swagger.io/terms/ // @contact.name Shikong // @contact.email 919411476@qq.com // @license.name Apache 2.0 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html // @BasePath / // @SecurityDefinitions.apikey Token // @In header // @Name token func main() { viper.SetConfigName("config") viper.SetConfigType("yaml") viper.AddConfigPath(".") viper.AddConfigPath("./config") if err := viper.ReadInConfig(); err != nil { if _, ok := err.(viper.ConfigFileNotFoundError); ok { logger.Log.Fatalf("未找到配置文件") } else { logger.Log.Fatalf("配置解析失败 %s", err) } } viper.WatchConfig() viper.OnConfigChange(func(in fsnotify.Event) { logger.Log.Infoln(in.Name) app.Run() }) app.Run() quit := make(chan os.Signal, 1) signal.Notify(quit, os.Interrupt) <-quit logger.Log.Infof("关闭服务") }