🔧 refactor(console): enhance URL validation and restructure settings module
- Refactor api_info.go to console.go for broader console settings support - Update URL regex pattern to accept both domain names and IP addresses - Add support for IPv4 addresses with optional port numbers - Improve validation to handle formats like http://192.168.1.1:8080 - Add ValidateConsoleSettings function for extensible settings validation - Maintain backward compatibility with existing ValidateApiInfo function - Add comprehensive comments explaining supported URL formats Fixes issue where IP-based URLs were incorrectly rejected as invalid format. Prepares infrastructure for additional console settings validation.
This commit is contained in:
@@ -9,12 +9,22 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValidateApiInfo 验证API信息格式
|
// ValidateConsoleSettings 验证控制台设置信息格式
|
||||||
func ValidateApiInfo(apiInfoStr string) error {
|
func ValidateConsoleSettings(settingsStr string, settingType string) error {
|
||||||
if apiInfoStr == "" {
|
if settingsStr == "" {
|
||||||
return nil // 空字符串是合法的
|
return nil // 空字符串是合法的
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch settingType {
|
||||||
|
case "ApiInfo":
|
||||||
|
return validateApiInfo(settingsStr)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("未知的设置类型:%s", settingType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// validateApiInfo 验证API信息格式
|
||||||
|
func validateApiInfo(apiInfoStr string) error {
|
||||||
var apiInfoList []map[string]interface{}
|
var apiInfoList []map[string]interface{}
|
||||||
if err := json.Unmarshal([]byte(apiInfoStr), &apiInfoList); err != nil {
|
if err := json.Unmarshal([]byte(apiInfoStr), &apiInfoList); err != nil {
|
||||||
return fmt.Errorf("API信息格式错误:%s", err.Error())
|
return fmt.Errorf("API信息格式错误:%s", err.Error())
|
||||||
@@ -103,6 +113,11 @@ func ValidateApiInfo(apiInfoStr string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateApiInfo 保持向后兼容的函数
|
||||||
|
func ValidateApiInfo(apiInfoStr string) error {
|
||||||
|
return validateApiInfo(apiInfoStr)
|
||||||
|
}
|
||||||
|
|
||||||
// GetApiInfo 获取API信息列表
|
// GetApiInfo 获取API信息列表
|
||||||
func GetApiInfo() []map[string]interface{} {
|
func GetApiInfo() []map[string]interface{} {
|
||||||
// 从OptionMap中获取API信息,如果不存在则返回空数组
|
// 从OptionMap中获取API信息,如果不存在则返回空数组
|
||||||
Reference in New Issue
Block a user