mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2024-11-16 07:02:20 +08:00
feat: add an option to listen on a specific IP address (#136)
This commit is contained in:
parent
7090eadfd5
commit
0d73552773
12
config.go
12
config.go
|
@ -15,14 +15,26 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"os"
|
"os"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initConfig() *Config {
|
func initConfig() *Config {
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
|
IP: "0.0.0.0",
|
||||||
Port: 1188,
|
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
|
// 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, "port", cfg.Port, "set up the port to listen on")
|
||||||
flag.IntVar(&cfg.Port, "p", cfg.Port, "set up the port to listen on")
|
flag.IntVar(&cfg.Port, "p", cfg.Port, "set up the port to listen on")
|
||||||
|
|
||||||
|
|
9
main.go
9
main.go
|
@ -60,7 +60,7 @@ func authMiddleware(cfg *Config) gin.HandlerFunc {
|
||||||
func main() {
|
func main() {
|
||||||
cfg := initConfig()
|
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 <i@leo.moe> and missuo <me@missuo.me>.")
|
fmt.Println("Developed by sjlleo <i@leo.moe> and missuo <me@missuo.me>.")
|
||||||
|
|
||||||
// Set Proxy
|
// Set Proxy
|
||||||
|
@ -255,10 +255,5 @@ func main() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
envPort, ok := os.LookupEnv("PORT")
|
r.Run(fmt.Sprintf("%v:%v", cfg.IP, cfg.Port))
|
||||||
if ok {
|
|
||||||
r.Run(":" + envPort)
|
|
||||||
} else {
|
|
||||||
r.Run(fmt.Sprintf(":%v", cfg.Port))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user