feat: 完善账号配置验证器
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
package github
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GitHubAccountConfigValidator GitHub账号配置验证器
|
||||||
|
type GitHubAccountConfigValidator struct{}
|
||||||
|
|
||||||
|
func (v *GitHubAccountConfigValidator) GetType() string {
|
||||||
|
return "github-account"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *GitHubAccountConfigValidator) Validate(config string) error {
|
||||||
|
// GitHub账号配置验证逻辑
|
||||||
|
var cfg GithubAccount
|
||||||
|
if err := json.Unmarshal([]byte(config), &cfg); err != nil {
|
||||||
|
return fmt.Errorf("解析GitHub账号配置失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Token == "" {
|
||||||
|
return fmt.Errorf("GitHub账号配置中Token不能为空")
|
||||||
|
}
|
||||||
|
if cfg.Owner == "" {
|
||||||
|
return fmt.Errorf("GitHub账号配置中Owner不能为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package onebot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AccountConfigValidator OneBot账号配置验证器接口
|
||||||
|
type OneBotAccountConfigValidator struct{}
|
||||||
|
|
||||||
|
func (v *OneBotAccountConfigValidator) GetType() string {
|
||||||
|
return "onebot"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *OneBotAccountConfigValidator) Validate(config string) error {
|
||||||
|
var cfg OneBotAccount
|
||||||
|
if err := json.Unmarshal([]byte(config), &cfg); err != nil {
|
||||||
|
return fmt.Errorf("解析OneBot账号配置失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Token == "" {
|
||||||
|
return fmt.Errorf("OneBot账号配置中Token不能为空")
|
||||||
|
}
|
||||||
|
if cfg.URL == "" {
|
||||||
|
return fmt.Errorf("OneBot账号配置中URL不能为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
package accountConfigChecker
|
package accountConfigChecker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ssdomei232/goodBaby/drivers/bilibili"
|
||||||
|
"github.com/ssdomei232/goodBaby/drivers/email"
|
||||||
|
"github.com/ssdomei232/goodBaby/drivers/github"
|
||||||
|
"github.com/ssdomei232/goodBaby/drivers/onebot"
|
||||||
|
)
|
||||||
|
|
||||||
func InitValidatorRegistry() *ValidatorRegistry {
|
func InitValidatorRegistry() *ValidatorRegistry {
|
||||||
registry := NewValidatorRegistry()
|
registry := NewValidatorRegistry()
|
||||||
|
|
||||||
// 注册所有规则验证器
|
// 注册所有账号验证器
|
||||||
// registry.Register(&bilibili.BilibiliAccountValidator{})
|
registry.Register(&bilibili.BilibiliAccountConfigValidator{})
|
||||||
|
registry.Register(&email.EmailAccountConfigValidator{})
|
||||||
|
registry.Register(&github.GitHubAccountConfigValidator{})
|
||||||
|
registry.Register(&onebot.OneBotAccountConfigValidator{})
|
||||||
|
|
||||||
return registry
|
return registry
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user