diff --git a/config.go b/config.go index b2ccb24e..203e17d6 100644 --- a/config.go +++ b/config.go @@ -15,14 +15,26 @@ package main import ( "flag" "os" + "fmt" ) func initConfig() *Config { cfg := &Config{ + IP: "0.0.0.0", Port: 1188, } + // IP flag + if ip, ok := os.LookupEnv("IP"); ok && ip != "" { + cfg.IP = ip + } + flag.StringVar(&cfg.IP, "ip", cfg.IP, "set up the IP address to bind to") + flag.StringVar(&cfg.IP, "i", cfg.IP, "set up the IP address to bind to") + // Port flag + if port, ok := os.LookupEnv("PORT"); ok && port != "" { + fmt.Sscanf(port, "%d", &cfg.Port) + } flag.IntVar(&cfg.Port, "port", cfg.Port, "set up the port to listen on") flag.IntVar(&cfg.Port, "p", cfg.Port, "set up the port to listen on") diff --git a/main.go b/main.go index 7d4af497..212ab8e2 100644 --- a/main.go +++ b/main.go @@ -60,7 +60,7 @@ func authMiddleware(cfg *Config) gin.HandlerFunc { func main() { cfg := initConfig() - fmt.Printf("DeepL X has been successfully launched! Listening on 0.0.0.0:%v\n", cfg.Port) + fmt.Printf("DeepL X has been successfully launched! Listening on %v:%v\n", cfg.IP, cfg.Port) fmt.Println("Developed by sjlleo and missuo .") // Set Proxy @@ -255,10 +255,5 @@ func main() { }) }) - envPort, ok := os.LookupEnv("PORT") - if ok { - r.Run(":" + envPort) - } else { - r.Run(fmt.Sprintf(":%v", cfg.Port)) - } + r.Run(fmt.Sprintf("%v:%v", cfg.IP, cfg.Port)) } diff --git a/types.go b/types.go index 9e9e2b73..1f0948f6 100644 --- a/types.go +++ b/types.go @@ -12,6 +12,7 @@ package main type Config struct { + IP string Port int Token string AuthKey string