91 lines
2.1 KiB
Go
91 lines
2.1 KiB
Go
// 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:
|
|
return consts.RequestDataLocationQuery.String()
|
|
case http.MethodPost:
|
|
fallthrough
|
|
case http.MethodPut:
|
|
fallthrough
|
|
case http.MethodPatch: // RFC 5789
|
|
fallthrough
|
|
case http.MethodDelete:
|
|
return consts.RequestDataLocationBody.String()
|
|
}
|
|
return consts.RequestDataLocationQuery.String()
|
|
}
|
|
|
|
// GetSwaggerType 基于输入的类型,
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 12:23 2024/4/22
|
|
func GetSwaggerType(inputType string) string {
|
|
for _, itemType := range consts.DataTypeBaseInt {
|
|
if itemType.String() == inputType {
|
|
return consts.SwaggerDataTypeInteger
|
|
}
|
|
}
|
|
for _, itemType := range consts.DataTypeBaseUint {
|
|
if itemType.String() == inputType {
|
|
return consts.SwaggerDataTypeInteger
|
|
}
|
|
}
|
|
for _, itemType := range consts.DataTypeBaseFloat {
|
|
if itemType.String() == inputType {
|
|
return consts.SwaggerDataTypeDouble
|
|
}
|
|
}
|
|
for _, itemType := range consts.DataTypeBaseString {
|
|
if itemType.String() == inputType {
|
|
return consts.SwaggerDataTypeString
|
|
}
|
|
}
|
|
for _, itemType := range consts.DataTypeBaseString {
|
|
if itemType.String() == inputType {
|
|
return consts.SwaggerDataTypeString
|
|
}
|
|
}
|
|
for _, itemType := range consts.DataTypeBaseBool {
|
|
if itemType.String() == inputType {
|
|
return consts.SwaggerDataTypeBoolean
|
|
}
|
|
}
|
|
if strings.HasPrefix(inputType, "[]") {
|
|
return consts.SwaggerDataTypeArray
|
|
}
|
|
if strings.HasPrefix(inputType, "map") {
|
|
return consts.SwaggerDataTypeObject
|
|
}
|
|
return inputType
|
|
}
|