功能:新增云管API与Web控制台并完成现场接入
This commit is contained in:
1 parent
18a9ce995d
commit
3fb7b4da8c
79 files changed
+17367
-3
No files matched your search
@@ -0,0 +1,39 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Mode, Address, DatabaseURL, JWTSecret, AdminUsername, AdminPassword string
|
||||
PVEURL, PVETokenID, PVETokenSecret, PVECAFile string
|
||||
}
|
||||
|
||||
func Load() (Config, error) {
|
||||
c := Config{Mode: env("VDI_MODE", "production"), Address: env("VDI_LISTEN", "127.0.0.1:8080"), DatabaseURL: os.Getenv("DATABASE_URL"), JWTSecret: os.Getenv("VDI_JWT_SECRET"), AdminUsername: os.Getenv("VDI_ADMIN_USERNAME"), AdminPassword: os.Getenv("VDI_ADMIN_PASSWORD"), PVEURL: os.Getenv("PVE_URL"), PVETokenID: os.Getenv("PVE_TOKEN_ID"), PVETokenSecret: os.Getenv("PVE_TOKEN_SECRET"), PVECAFile: os.Getenv("PVE_CA_FILE")}
|
||||
if c.Mode != "demo" && c.Mode != "production" {
|
||||
return c, fmt.Errorf("VDI_MODE must be demo or production")
|
||||
}
|
||||
if c.DatabaseURL == "" {
|
||||
return c, fmt.Errorf("DATABASE_URL is required")
|
||||
}
|
||||
if len(c.JWTSecret) < 32 {
|
||||
return c, fmt.Errorf("VDI_JWT_SECRET must contain at least 32 characters")
|
||||
}
|
||||
if c.Mode == "production" && strings.TrimSpace(c.AdminUsername) == "" {
|
||||
return c, fmt.Errorf("production requires VDI_ADMIN_USERNAME")
|
||||
}
|
||||
if c.PVEURL != "" && (c.PVETokenID == "" || c.PVETokenSecret == "") {
|
||||
return c, fmt.Errorf("PVE_TOKEN_ID and PVE_TOKEN_SECRET are required with PVE_URL")
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func env(key, fallback string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Reference in new issue
Block a user