forked from OwO-Network/DeepLX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
75 lines (65 loc) · 1.64 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* @Author: Vincent Yang
* @Date: 2024-04-23 00:39:03
* @LastEditors: Vincent Yang
* @LastEditTime: 2024-09-17 19:34:32
* @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"
"fmt"
"os"
)
type Config struct {
IP string
Port int
Token string
DlSession string
Proxy string
}
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")
// 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
}
}
// 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
}
}
flag.Parse()
return cfg
}