feat: multi user template

This commit is contained in:
naiba
2024-12-06 23:19:28 +08:00
parent 8755b65ac5
commit 9b0697491d
7 changed files with 62 additions and 14 deletions

View File

@@ -27,6 +27,7 @@ type Config struct {
Language string `mapstructure:"language" json:"language"` // 系统语言,默认 zh_CN
SiteName string `mapstructure:"site_name" json:"site_name"`
UserTemplate string `mapstructure:"user_template" json:"user_template,omitempty"`
JWTSecretKey string `mapstructure:"jwt_secret_key" json:"jwt_secret_key,omitempty"`
AgentSecretKey string `mapstructure:"agent_secret_key" json:"agent_secret_key,omitempty"`
ListenPort uint `mapstructure:"listen_port" json:"listen_port,omitempty"`
@@ -55,7 +56,7 @@ type Config struct {
}
// Read 读取配置文件并应用
func (c *Config) Read(path string) error {
func (c *Config) Read(path string, userTemplates []UserTemplate) error {
c.k = koanf.New(".")
c.filePath = path
@@ -87,6 +88,16 @@ func (c *Config) Read(path string) error {
if c.Location == "" {
c.Location = "Asia/Shanghai"
}
var userTemplateValid bool
for _, v := range userTemplates {
if v.Path == c.UserTemplate {
userTemplateValid = true
break
}
}
if c.UserTemplate == "" || !userTemplateValid {
c.UserTemplate = "user-dist"
}
if c.AvgPingCount == 0 {
c.AvgPingCount = 2
}

View File

@@ -11,14 +11,24 @@ type SettingForm struct {
CustomCode string `json:"custom_code,omitempty" validate:"optional"`
CustomCodeDashboard string `json:"custom_code_dashboard,omitempty" validate:"optional"`
RealIPHeader string `json:"real_ip_header,omitempty" validate:"optional"` // 真实IP
UserTemplate string `json:"user_template,omitempty" validate:"optional"`
TLS bool `json:"tls,omitempty" validate:"optional"`
EnableIPChangeNotification bool `json:"enable_ip_change_notification,omitempty" validate:"optional"`
EnablePlainIPInNotification bool `json:"enable_plain_ip_in_notification,omitempty" validate:"optional"`
}
type UserTemplate struct {
Path string `json:"path,omitempty"`
Name string `json:"name,omitempty"`
GitHub string `json:"github,omitempty"`
Author string `json:"author,omitempty"`
Community bool `json:"community,omitempty"`
}
type SettingResponse struct {
Config
Version string `json:"version,omitempty"`
Version string `json:"version,omitempty"`
UserTemplates []UserTemplate `json:"user_templates,omitempty"`
}