package main import ( "fmt" "git.jmbit.de/jmb/patchman/client/api" "github.com/gin-gonic/gin" "github.com/spf13/viper" "github.com/go-co-op/gocron" "log" "net/http" "os" ) // loadConfig reads in the Config file(s) and sets defaults. func loadConfig() { viper.SetDefault("server.ip", "127.0.0.1") viper.SetDefault("server.port", 8008) viper.SetConfigName("client.yaml") viper.SetConfigType("yaml") if os.Getenv("GIN_MODE") == "release" { viper.AddConfigPath("/etc/patchman/") } else { viper.AddConfigPath("./") } // Read Config and handle produced error, separating out File not found if err := viper.ReadInConfig(); err != nil { if _, ok := err.(viper.ConfigFileNotFoundError); ok { // Config file not found; ignore error if desired } else { // Config file was found but another error was produced } } } s := gocron.NewScheduler(time.UTC) func setupRouter() *gin.Engine { router := gin.Default() // Ping test router.GET("/ping", func(c *gin.Context) { c.String(http.StatusOK, "pong\n") }) return router } func main() { loadConfig() router := setupRouter() router = api.GroupV0(router) err := router.Run(fmt.Sprintf("%s:%d", viper.Get("address"), viper.Get("port"))) if err != nil { log.Fatal(err) } }