Files
Prism/internal/settings/defaults.go
T
rose_cat707 af5596aea3
CI / test (push) Successful in 1m24s
CI / docker (push) Failing after 22s
feat: Prism HTTP/SOCKS5 代理网关及管理台
Go 控制面(SQLite + REST API)嵌入 Mihomo 数据面,Vue 3 多语言 Web 管理台。
含订阅/节点/规则/出站/监控/日志、OpenAPI、API Key、Gitea Actions CI 与开源文档;
CI 适配自托管 runner(国内 Go 镜像、act 容器构建、docker.sock 挂载说明)。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 14:16:48 +08:00

62 lines
1.6 KiB
Go

package settings
import (
"strconv"
"strings"
"github.com/prism/proxy/internal/geodata"
)
// Display merges stored settings with effective defaults for the settings UI.
func Display(raw map[string]string) map[string]string {
out := make(map[string]string, len(raw)+8)
for k, v := range raw {
out[k] = v
}
applyGeoDisplayDefaults(out)
applyScalarDisplayDefaults(out)
applyLocaleDisplayDefaults(out)
return out
}
// NormalizeSubmit clears values that match built-in defaults so empty means default.
func NormalizeSubmit(req map[string]string) {
normalizeGeoSubmit(req)
normalizeLocaleSubmit(req)
}
func applyGeoDisplayDefaults(out map[string]string) {
def := geodata.DefaultConfig()
if strings.TrimSpace(out["geo_country_mmdb_url"]) == "" {
out["geo_country_mmdb_url"] = def.CountryMmdbURL
}
if strings.TrimSpace(out["geo_geoip_url"]) == "" {
out["geo_geoip_url"] = def.GeoIPURL
}
if strings.TrimSpace(out["geo_geosite_url"]) == "" {
out["geo_geosite_url"] = def.GeoSiteURL
}
}
func normalizeGeoSubmit(req map[string]string) {
def := geodata.DefaultConfig()
if strings.TrimSpace(req["geo_country_mmdb_url"]) == def.CountryMmdbURL {
req["geo_country_mmdb_url"] = ""
}
if strings.TrimSpace(req["geo_geoip_url"]) == def.GeoIPURL {
req["geo_geoip_url"] = ""
}
if strings.TrimSpace(req["geo_geosite_url"]) == def.GeoSiteURL {
req["geo_geosite_url"] = ""
}
}
func applyScalarDisplayDefaults(out map[string]string) {
if strings.TrimSpace(out["login_max_attempts"]) == "" {
out["login_max_attempts"] = strconv.Itoa(5)
}
if strings.TrimSpace(out["login_lock_minutes"]) == "" {
out["login_lock_minutes"] = strconv.Itoa(15)
}
}