交付双端基础、实时联系人和隔离浏览器

This commit is contained in:
xhgit committed 2026-11-13 18:03:32 +08:00
1 parent 43687d5e7e
commit 67fef3ff87
59 files changed
+5094 -1

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
package config
import (
"errors"
"os"
"strings"
"time"
)
type Config struct {
Addr, DatabaseURL, RedisURL string
Origins map[string]bool
SessionTTL time.Duration
}
func Load() (Config, error) {
c := Config{
Addr: os.Getenv("XHCHAT_ADDR"),
DatabaseURL: os.Getenv("DATABASE_URL"),
RedisURL: os.Getenv("REDIS_URL"),
Origins: make(map[string]bool),
SessionTTL: 12 * time.Hour,
}
if c.Addr == "" {
c.Addr = "127.0.0.1:8080"
}
for _, origin := range strings.Split(os.Getenv("XHCHAT_ORIGINS"), ",") {
if origin = strings.TrimSpace(origin); origin != "" {
c.Origins[origin] = true
}
}
if c.DatabaseURL == "" || c.RedisURL == "" || len(c.Origins) == 0 {
return Config{}, errors.New("DATABASE_URL, REDIS_URL and XHCHAT_ORIGINS are required")
}
return c, nil
}