2024-04-23 12:50:11 +08:00
|
|
|
/*
|
|
|
|
* @Author: Vincent Yang
|
|
|
|
* @Date: 2024-04-23 00:39:03
|
2024-09-18 07:34:32 +08:00
|
|
|
* @LastEditors: Vincent Yang
|
|
|
|
* @LastEditTime: 2024-09-17 19:34:32
|
2024-04-23 12:50:11 +08:00
|
|
|
* @FilePath: /DeepLX/config.go
|
|
|
|
* @Telegram: https://t.me/missuo
|
|
|
|
* @GitHub: https://github.com/missuo
|
|
|
|
*
|
|
|
|
* Copyright © 2024 by Vincent, All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2024-08-15 19:19:12 +08:00
|
|
|
"fmt"
|
2024-09-17 00:08:13 +08:00
|
|
|
"os"
|
2024-04-23 12:50:11 +08:00
|
|
|
)
|
|
|
|
|
2024-09-17 00:08:13 +08:00
|
|
|
type Config struct {
|
|
|
|
IP string
|
|
|
|
Port int
|
|
|
|
Token string
|
|
|
|
DlSession string
|
|
|
|
Proxy string
|
|
|
|
}
|
|
|
|
|
2024-04-23 12:50:11 +08:00
|
|
|
func initConfig() *Config {
|
|
|
|
cfg := &Config{
|
2024-09-17 00:08:13 +08:00
|
|
|
IP: "0.0.0.0",
|
2024-04-23 12:50:11 +08:00
|
|
|
Port: 1188,
|
|
|
|
}
|
|
|
|
|
2024-08-15 19:19:12 +08:00
|
|
|
// 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")
|
|
|
|
|
2024-04-23 12:50:11 +08:00
|
|
|
// Port flag
|
2024-08-15 19:19:12 +08:00
|
|
|
if port, ok := os.LookupEnv("PORT"); ok && port != "" {
|
|
|
|
fmt.Sscanf(port, "%d", &cfg.Port)
|
|
|
|
}
|
2024-04-23 12:50:11 +08:00
|
|
|
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")
|
|
|
|
|
|
|
|
// DL Session flag
|
|
|
|
flag.StringVar(&cfg.DlSession, "s", "", "set the dl-session for /v1/translate endpoint")
|
|
|
|
if cfg.DlSession == "" {
|
|
|
|
if dlSession, ok := os.LookupEnv("DL_SESSION"); ok {
|
|
|
|
cfg.DlSession = dlSession
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Access token flag
|
|
|
|
flag.StringVar(&cfg.Token, "token", "", "set the access token for /translate endpoint")
|
|
|
|
if cfg.Token == "" {
|
|
|
|
if token, ok := os.LookupEnv("TOKEN"); ok {
|
|
|
|
cfg.Token = token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 03:09:20 +08:00
|
|
|
// HTTP Proxy flag
|
|
|
|
flag.StringVar(&cfg.Proxy, "proxy", "", "set the proxy URL for HTTP requests")
|
|
|
|
if cfg.Proxy == "" {
|
|
|
|
if proxy, ok := os.LookupEnv("PROXY"); ok {
|
|
|
|
cfg.Proxy = proxy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-23 12:50:11 +08:00
|
|
|
flag.Parse()
|
|
|
|
return cfg
|
|
|
|
}
|