2023-06-30 14:54:43 +08:00

68 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package apiResponse
import (
"hospital-admin-api/api/model"
"strconv"
)
// getApiPage 获取接口列表-分页
type getApiPage struct {
APIID string `json:"api_id"` // 主键id
APIName string `json:"api_name"` // api名称
APIPath string `json:"api_path"` // 接口路径(全路径 id为:id
APIMethod string `json:"api_method"` // 请求类型
IsAuth int `json:"is_auth"` // 是否验证权限0:否 1:是)
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// 接口详情
type getApi struct {
APIID string `json:"api_id"` // 主键id
APIName string `json:"api_name"` // api名称
APIPath string `json:"api_path"` // 接口路径(全路径 id为:id
APIMethod string `json:"api_method"` // 请求类型
IsAuth int `json:"is_auth"` // 是否验证权限0:否 1:是)
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// GetApiPageResponse 获取接口列表-分页
func GetApiPageResponse(adminApi []*model.AdminAPI) []getApiPage {
// 处理返回值
getApiPageResponses := make([]getApiPage, len(adminApi))
if len(adminApi) > 0 {
for i, v := range adminApi {
// 将原始结构体转换为新结构体
getApiPageResponse := getApiPage{
APIID: strconv.Itoa(int(v.APIID)),
APIName: v.APIName,
APIPath: v.APIPath,
APIMethod: v.APIMethod,
IsAuth: v.IsAuth,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
getApiPageResponses[i] = getApiPageResponse
}
}
return getApiPageResponses
}
// GetApiResponse 接口详情
func GetApiResponse(adminApi *model.AdminAPI) *getApi {
return &getApi{
APIID: strconv.Itoa(int(adminApi.APIID)),
APIName: adminApi.APIName,
APIPath: adminApi.APIPath,
APIMethod: adminApi.APIMethod,
IsAuth: adminApi.IsAuth,
CreatedAt: adminApi.CreatedAt,
UpdatedAt: adminApi.UpdatedAt,
}
}