feat(equalize): Enhance EqualizeConfig to support external API URL
- Added ExternalAPIURL to EqualizeConfig for public EQ interface usage. - Updated loadEqualize function to initialize ExternalAPIURL from environment variable or default value. - Refactored reqEqualize method to accept apiURL as a parameter for improved flexibility. - Introduced eqAPIURL method to determine the appropriate API URL based on the source.
This commit is contained in:
@@ -2,19 +2,32 @@ package config
|
||||
|
||||
import "os"
|
||||
|
||||
const defaultExternalEQAPIURL = "https://autoeq.app/equalize"
|
||||
|
||||
type EqualizeConfig struct {
|
||||
APIURL string
|
||||
APIURL string // 内网 EQ 接口(正式环境 Eafonyoung 源使用)
|
||||
ExternalAPIURL string // 公网 EQ 接口(正式环境非 Eafonyoung 源使用)
|
||||
}
|
||||
|
||||
func loadEqualize(env string) EqualizeConfig {
|
||||
external := getEnv("EQ_EXTERNAL_API_URL", defaultExternalEQAPIURL)
|
||||
if os.Getenv("EQ_API_URL") != "" {
|
||||
return EqualizeConfig{APIURL: os.Getenv("EQ_API_URL")}
|
||||
return EqualizeConfig{
|
||||
APIURL: os.Getenv("EQ_API_URL"),
|
||||
ExternalAPIURL: external,
|
||||
}
|
||||
}
|
||||
|
||||
switch env {
|
||||
case "production":
|
||||
return EqualizeConfig{APIURL: "http://172.31.18.70:8000/equalize"}
|
||||
return EqualizeConfig{
|
||||
APIURL: "http://172.31.18.70:8000/equalize",
|
||||
ExternalAPIURL: external,
|
||||
}
|
||||
default:
|
||||
return EqualizeConfig{APIURL: "https://autoeq.app/equalize"}
|
||||
return EqualizeConfig{
|
||||
APIURL: defaultExternalEQAPIURL,
|
||||
ExternalAPIURL: external,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user