feat: add environment variable support for server configuration

This commit is contained in:
SunBK201 2025-12-11 20:09:57 +08:00
parent 2633d4d360
commit 3e72305ac2
2 changed files with 36 additions and 1 deletions

View File

@ -17,6 +17,13 @@ WORKDIR /app
COPY --from=builder /app/ua3f .
ENV UA3F_SERVER_MODE=SOCKS5
ENV UA3F_PORT=1080
ENV UA3F_REWRITE_MODE=GLOBAL
ENV UA3F_PAYLOAD_UA=FFF
ENV UA3F_UA_REGEX=
ENV UA3F_PARTIAL_REPLACE=0
EXPOSE 1080
ENTRYPOINT ["/app/ua3f", "-b", "0.0.0.0"]

View File

@ -95,7 +95,35 @@ func Parse() (*Config, bool) {
cfg.ListenAddr = fmt.Sprintf("0.0.0.0:%d", port)
}
// Parse other options from environment variables
if os.Getenv("UA3F_SERVER_MODE") != "" {
cfg.ServerMode = ServerMode(strings.ToUpper(os.Getenv("UA3F_SERVER_MODE")))
}
if os.Getenv("UA3F_PORT") != "" {
var p int
_, err := fmt.Sscanf(os.Getenv("UA3F_PORT"), "%d", &p)
if err == nil {
cfg.Port = p
cfg.ListenAddr = fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.Port)
}
}
if os.Getenv("UA3F_REWRITE_MODE") != "" {
cfg.RewriteMode = RewriteMode(strings.ToUpper(os.Getenv("UA3F_REWRITE_MODE")))
}
if os.Getenv("UA3F_PAYLOAD_UA") != "" {
cfg.PayloadUA = os.Getenv("UA3F_PAYLOAD_UA")
}
if os.Getenv("UA3F_UA_REGEX") != "" {
cfg.UARegex = os.Getenv("UA3F_UA_REGEX")
}
if os.Getenv("UA3F_PARTIAL_REPLACE") == "1" {
cfg.PartialReplace = true
}
if os.Getenv("UA3F_TCPTS") == "1" {
cfg.DelTCPTimestamp = true
}