fix bugs
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
@@ -14,15 +15,14 @@ var Cfg *Config
|
||||
// Config 结构体存储应用配置
|
||||
type Config struct {
|
||||
// 服务器配置
|
||||
ServerPort int
|
||||
ServerHost string
|
||||
Port int
|
||||
ReadTimeout time.Duration
|
||||
WriteTimeout time.Duration
|
||||
|
||||
// PassKey配置
|
||||
AppName string
|
||||
Domain string
|
||||
AppURL string
|
||||
AppName string // 依赖方(Relying Party)显示名称
|
||||
RPID string // 依赖方ID(通常为域名)
|
||||
RPOrigins []string // 依赖方源(URL)
|
||||
WebAuthnTimeout time.Duration
|
||||
ChallengeExpiration time.Duration
|
||||
|
||||
@@ -70,12 +70,12 @@ func init() {
|
||||
// LoadConfig 从环境变量加载配置
|
||||
func LoadConfig() (*Config, error) {
|
||||
cfg := &Config{
|
||||
AppName: "OpenTeam",
|
||||
Domain: "localhost",
|
||||
AppURL: "https://localhost:5173",
|
||||
AppName: "OpenTeam",
|
||||
RPID: "localhost", // 域名
|
||||
RPOrigins: []string{"https://localhost:5173"},
|
||||
// 默认值设置
|
||||
ServerPort: 8080,
|
||||
ServerHost: "0.0.0.0",
|
||||
Port: 80,
|
||||
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
|
||||
@@ -91,8 +91,8 @@ func LoadConfig() (*Config, error) {
|
||||
|
||||
// 系统设置
|
||||
AllowRegister: false,
|
||||
UnlimitedQuota: false,
|
||||
DefaultActive: false,
|
||||
UnlimitedQuota: true,
|
||||
DefaultActive: true,
|
||||
|
||||
UsageWorker: 1,
|
||||
UsageChanSize: 1000,
|
||||
@@ -103,26 +103,30 @@ func LoadConfig() (*Config, error) {
|
||||
if appName := os.Getenv("APP_NAME"); appName != "" {
|
||||
cfg.AppName = appName
|
||||
}
|
||||
if domain := os.Getenv("DOMAIN"); domain != "" {
|
||||
cfg.Domain = domain
|
||||
if domain := os.Getenv("RPID"); domain != "" {
|
||||
cfg.RPID = domain
|
||||
}
|
||||
if appURL := os.Getenv("APP_URL"); appURL != "" {
|
||||
cfg.AppURL = appURL
|
||||
if origin := os.Getenv("RPORIGINS"); origin != "" {
|
||||
var rpos []string
|
||||
list := strings.Split(origin, ",")
|
||||
for _, l := range list {
|
||||
trimmedl := strings.TrimSpace(l)
|
||||
if trimmedl != "" {
|
||||
rpos = append(rpos, trimmedl)
|
||||
}
|
||||
}
|
||||
cfg.RPOrigins = rpos
|
||||
}
|
||||
|
||||
// 服务器配置
|
||||
if port := os.Getenv("SERVER_PORT"); port != "" {
|
||||
if port := os.Getenv("PORT"); port != "" {
|
||||
if p, err := strconv.Atoi(port); err == nil {
|
||||
cfg.ServerPort = p
|
||||
cfg.Port = p
|
||||
} else {
|
||||
return nil, fmt.Errorf("无效的SERVER_PORT: %s", port)
|
||||
return nil, fmt.Errorf("PORT: %s", port)
|
||||
}
|
||||
}
|
||||
|
||||
if host := os.Getenv("SERVER_HOST"); host != "" {
|
||||
cfg.ServerHost = host
|
||||
}
|
||||
|
||||
if timeout := os.Getenv("READ_TIMEOUT"); timeout != "" {
|
||||
if t, err := strconv.Atoi(timeout); err == nil {
|
||||
cfg.ReadTimeout = time.Duration(t) * time.Second
|
||||
|
||||
Reference in New Issue
Block a user