新增代理服务与边缘节点注册功能
This commit is contained in:
161
server/pkg/env/env.go
vendored
161
server/pkg/env/env.go
vendored
@@ -2,104 +2,139 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
var (
|
||||
AppCtrlPort uint16
|
||||
AppDataPort uint16
|
||||
AppWebPort uint16
|
||||
AppLogMode string
|
||||
AppCtrlPort uint16 = 18080
|
||||
AppDataPort uint16 = 18081
|
||||
AppWebPort uint16 = 8848
|
||||
AppLogMode string = "dev"
|
||||
|
||||
ClientId string
|
||||
ClientSecret string
|
||||
|
||||
DbHost string
|
||||
DbPort uint16
|
||||
DbPort uint16 = 5432
|
||||
DbDatabase string
|
||||
DbUsername string
|
||||
DbPassword string
|
||||
DbTimezone string
|
||||
DbTimezone string = "Asia/Shanghai"
|
||||
|
||||
EndpointOnline string
|
||||
EndpointOffline string
|
||||
)
|
||||
|
||||
func Init() {
|
||||
|
||||
// AppCtrlPort
|
||||
appCtrlPortStr := os.Getenv("APP_CTRL_PORT")
|
||||
if appCtrlPortStr == "" {
|
||||
panic("环境变量 APP_CTRL_PORT 未设置")
|
||||
}
|
||||
appCtrlPort, err := strconv.ParseUint(appCtrlPortStr, 10, 16)
|
||||
var err = godotenv.Load()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 APP_CTRL_PORT 格式错误: %v", err))
|
||||
slog.Debug("没有本地环境变量文件")
|
||||
}
|
||||
AppCtrlPort = uint16(appCtrlPort)
|
||||
var value string
|
||||
|
||||
// AppDataPort
|
||||
appDataPortStr := os.Getenv("APP_DATA_PORT")
|
||||
if appDataPortStr == "" {
|
||||
panic("环境变量 APP_DATA_PORT 未设置")
|
||||
value = os.Getenv("APP_CTRL_PORT")
|
||||
if value != "" {
|
||||
appCtrlPort, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 APP_CTRL_PORT 格式错误: %v", err))
|
||||
}
|
||||
AppCtrlPort = uint16(appCtrlPort)
|
||||
}
|
||||
appDataPort, err := strconv.ParseUint(appDataPortStr, 10, 16)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 APP_DATA_PORT 格式错误: %v", err))
|
||||
}
|
||||
AppDataPort = uint16(appDataPort)
|
||||
|
||||
// AppWebPort
|
||||
appWebPortStr := os.Getenv("APP_WEB_PORT")
|
||||
if appWebPortStr == "" {
|
||||
appWebPortStr = "8848"
|
||||
value = os.Getenv("APP_DATA_PORT")
|
||||
if value != "" {
|
||||
appDataPort, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 APP_DATA_PORT 格式错误: %v", err))
|
||||
}
|
||||
AppDataPort = uint16(appDataPort)
|
||||
}
|
||||
appWebPort, err := strconv.ParseUint(appWebPortStr, 10, 16)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 APP_WEB_PORT 格式错误: %v", err))
|
||||
}
|
||||
AppWebPort = uint16(appWebPort)
|
||||
|
||||
// AppLogMode
|
||||
appLogMode := os.Getenv("APP_LOG_MODE")
|
||||
if appLogMode == "" {
|
||||
AppLogMode = "dev"
|
||||
value = os.Getenv("APP_WEB_PORT")
|
||||
if value != "" {
|
||||
appWebPort, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 APP_WEB_PORT 格式错误: %v", err))
|
||||
}
|
||||
AppWebPort = uint16(appWebPort)
|
||||
}
|
||||
AppLogMode = appLogMode
|
||||
|
||||
// DbHost
|
||||
DbHost = os.Getenv("DB_HOST")
|
||||
if DbHost == "" {
|
||||
value = os.Getenv("APP_LOG_MODE")
|
||||
if value != "" {
|
||||
AppLogMode = value
|
||||
}
|
||||
|
||||
value = os.Getenv("CLIENT_ID")
|
||||
if value != "" {
|
||||
ClientId = value
|
||||
} else {
|
||||
panic("环境变量 CLIENT_ID 未设置")
|
||||
}
|
||||
|
||||
value = os.Getenv("CLIENT_SECRET")
|
||||
if value != "" {
|
||||
ClientSecret = value
|
||||
} else {
|
||||
panic("环境变量 CLIENT_SECRET 未设置")
|
||||
}
|
||||
|
||||
value = os.Getenv("DB_HOST")
|
||||
if value != "" {
|
||||
DbHost = os.Getenv("DB_HOST")
|
||||
} else {
|
||||
panic("环境变量 DB_HOST 未设置")
|
||||
}
|
||||
|
||||
// DbPort
|
||||
dbPortStr := os.Getenv("DB_PORT")
|
||||
if dbPortStr == "" {
|
||||
dbPortStr = "5432"
|
||||
value = os.Getenv("DB_PORT")
|
||||
if value != "" {
|
||||
dbPort, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 DB_PORT 格式错误: %v", err))
|
||||
}
|
||||
DbPort = uint16(dbPort)
|
||||
}
|
||||
dbPort, err := strconv.ParseUint(dbPortStr, 10, 16)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 DB_PORT 格式错误: %v", err))
|
||||
}
|
||||
DbPort = uint16(dbPort)
|
||||
|
||||
// DbDatabase
|
||||
DbDatabase = os.Getenv("DB_DATABASE")
|
||||
if DbDatabase == "" {
|
||||
value = os.Getenv("DB_DATABASE")
|
||||
if value != "" {
|
||||
DbDatabase = value
|
||||
} else {
|
||||
panic("环境变量 DB_DATABASE 未设置")
|
||||
}
|
||||
|
||||
// DbUsername
|
||||
DbUsername = os.Getenv("DB_USERNAME")
|
||||
if DbUsername == "" {
|
||||
value = os.Getenv("DB_USERNAME")
|
||||
if value != "" {
|
||||
DbUsername = value
|
||||
} else {
|
||||
panic("环境变量 DB_USERNAME 未设置")
|
||||
}
|
||||
|
||||
// DbPassword
|
||||
DbPassword = os.Getenv("DB_PASSWORD")
|
||||
if DbPassword == "" {
|
||||
value = os.Getenv("DB_PASSWORD")
|
||||
if value != "" {
|
||||
DbPassword = value
|
||||
} else {
|
||||
panic("环境变量 DB_PASSWORD 未设置")
|
||||
}
|
||||
|
||||
// DbTimezone
|
||||
DbTimezone = os.Getenv("DB_TIMEZONE")
|
||||
if DbTimezone == "" {
|
||||
DbTimezone = "Asia/Shanghai"
|
||||
value = os.Getenv("DB_TIMEZONE")
|
||||
if value != "" {
|
||||
DbTimezone = value
|
||||
}
|
||||
|
||||
value = os.Getenv("ENDPOINT_ONLINE")
|
||||
if value != "" {
|
||||
EndpointOnline = value
|
||||
} else {
|
||||
panic("环境变量 ENDPOINT_ONLINE 未设置")
|
||||
}
|
||||
|
||||
value = os.Getenv("ENDPOINT_OFFLINE")
|
||||
if value != "" {
|
||||
EndpointOffline = value
|
||||
} else {
|
||||
panic("环境变量 ENDPOINT_OFFLINE 未设置")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user