♻️ refactor(setting): move API info functions to dedicated module
Move validateApiInfo and getApiInfo functions from controller layer to setting/api_info.go to improve code organization and separation of concerns. Changes: - Create setting/api_info.go with ValidateApiInfo() and GetApiInfo() functions - Remove validateApiInfo function from controller/option.go - Remove getApiInfo function from controller/misc.go - Update function calls to use setting package - Clean up unused imports (net/url, regexp, fmt) in controller/option.go This refactoring aligns the API info configuration management with the existing pattern used by other setting modules (chat.go, group_ratio.go, rate_limit.go, etc.) and improves code reusability and maintainability.
This commit is contained in:
@@ -74,33 +74,12 @@ func GetStatus(c *gin.Context) {
|
||||
"oidc_client_id": system_setting.GetOIDCSettings().ClientId,
|
||||
"oidc_authorization_endpoint": system_setting.GetOIDCSettings().AuthorizationEndpoint,
|
||||
"setup": constant.Setup,
|
||||
"api_info": getApiInfo(),
|
||||
"api_info": setting.GetApiInfo(),
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func getApiInfo() []map[string]interface{} {
|
||||
// 从OptionMap中获取API信息,如果不存在则返回空数组
|
||||
common.OptionMapRWMutex.RLock()
|
||||
apiInfoStr, exists := common.OptionMap["ApiInfo"]
|
||||
common.OptionMapRWMutex.RUnlock()
|
||||
|
||||
if !exists || apiInfoStr == "" {
|
||||
// 如果没有配置,返回空数组
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
|
||||
// 解析存储的API信息
|
||||
var apiInfo []map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(apiInfoStr), &apiInfo); err != nil {
|
||||
// 如果解析失败,返回空数组
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
|
||||
return apiInfo
|
||||
}
|
||||
|
||||
func GetNotice(c *gin.Context) {
|
||||
common.OptionMapRWMutex.RLock()
|
||||
defer common.OptionMapRWMutex.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user