api-doc/util/tool.go

65 lines
1.5 KiB
Go
Raw Normal View History

// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-04-22 11:15
package util
import (
"git.zhangdeman.cn/zhangdeman/consts"
"net/http"
"strings"
)
// GetParameterDefaultLocation 获取参数的默认位置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:16 2024/4/22
func GetParameterDefaultLocation(requestMethod string) string {
requestMethod = strings.ToUpper(requestMethod)
// 没指定参数位置
switch requestMethod {
case http.MethodGet:
fallthrough
case http.MethodHead:
fallthrough
case http.MethodConnect:
fallthrough
case http.MethodOptions:
fallthrough
case http.MethodTrace:
2025-02-07 21:27:33 +08:00
return consts.RequestDataLocationQuery.String()
case http.MethodPost:
fallthrough
case http.MethodPut:
fallthrough
case http.MethodPatch: // RFC 5789
fallthrough
case http.MethodDelete:
2025-02-07 21:27:33 +08:00
return consts.RequestDataLocationBody.String()
}
2025-02-07 21:27:33 +08:00
return consts.RequestDataLocationQuery.String()
}
2024-04-22 18:21:46 +08:00
// GetSwaggerType 基于输入的类型,
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:23 2024/4/22
func GetSwaggerType(inputType string) string {
convertTable := map[string]string{
2025-02-07 21:27:33 +08:00
consts.DataTypeString.String(): "string",
consts.DataTypeInt.String(): "integer",
consts.DataTypeUint.String(): "integer",
consts.DataTypeFloat.String(): "number",
consts.DataTypeBool.String(): "boolean",
2024-04-22 18:21:46 +08:00
}
if _, exist := convertTable[inputType]; exist {
return convertTable[inputType]
}
return inputType
}