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
}