-
Notifications
You must be signed in to change notification settings - Fork 0
/
define.go
122 lines (97 loc) · 3.24 KB
/
define.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package goapi
import (
"io"
"mime/multipart"
"net/http"
"reflect"
)
const inTypeHeader = "header"
const inTypeCookie = "cookie"
const inTypePath = "path"
const inTypeQuery = "query"
const inTypeBody = "body"
const inTypeForm = "form" // default application/x-www-form-urlencoded, If a inTypeFile exists, it becomes 'multipart/form-data'
const inTypeFile = "file" // default multipart/form-data
const inTypeSecurityHTTPBearer = "HTTPBearer"
const inTypeSecurityHTTPBearerJWT = "HTTPBearerJWT"
const inTypeSecurityHTTPBasic = "HTTPBasic"
const inTypeSecurityApiKey = "ApiKey"
var inTypes = []string{
inTypeHeader,
inTypeCookie,
inTypePath,
inTypeQuery,
inTypeBody,
inTypeForm,
inTypeFile,
}
type MediaType string
const jsonType = "json"
const xmlType = "xml"
const omitempty = "omitempty"
const JSON MediaType = "application/json"
const XML MediaType = "application/xml"
const formUrlencoded MediaType = "application/x-www-form-urlencoded"
const formMultipart MediaType = "multipart/form-data"
var mediaTypeToTypeMap = map[MediaType]string{
JSON: jsonType,
XML: xmlType,
}
var typeToMediaTypeMap = map[string]MediaType{
jsonType: JSON,
xmlType: XML,
}
var bodyMediaTypes = []MediaType{
JSON,
XML,
}
const prefixTempStruct = "tmp_"
const tagRegexp = "regexp" // VALIDATION. openapi's pattern
const tagDesc = "desc" // openapi's description
const tagEnum = "enum" // openapi's enum
const tagDefault = "default" // openapi's default
const tagExample = "example" // openapi's example
const tagLt = "lt" // VALIDATION. openapi's exclusiveMaximum
const tagLte = "lte" // VALIDATION. openapi's maximum
const tagGt = "gt" // VALIDATION. openapi's exclusiveMinimum
const tagGte = "gte" // VALIDATION. openapi's minimum
const tagMultiple = "multiple" // VALIDATION. openapi's multipleOf
const tagMax = "max" // VALIDATION. openapi's maxLength,maxItems,maxProperties
const tagMin = "min" // VALIDATION. openapi's minLength,minItems,minProperties
const tagUnique = "unique" // VALIDATION. openapi's uniqueItems
const tagPath = "path"
const tagMethod = "method"
const tagSummary = "summary"
const tagTags = "tags"
var tagVariableNames = []string{
tagSummary,
tagDesc,
}
const validErrorCode = 422
type LogLevel uint
var logLevel LogLevel = LogInfo | LogDebug | LogWarning | LogError | LogFail
const (
LogInfo LogLevel = 1 << iota
LogDebug
LogWarning
LogError
LogFail
)
var securityTypeHTTPBearer = reflect.TypeOf(new(HTTPBearer)).Elem()
var securityTypeHTTPBearerJWT = reflect.TypeOf(new(HTTPBearerJWT)).Elem()
var securityTypeHTTPBasic = reflect.TypeOf(new(HTTPBasic)).Elem()
var securityTypeApiKey = reflect.TypeOf(new(ApiKey)).Elem()
var typeResponse = reflect.TypeOf(new(Response)).Elem()
var securityTypes = []reflect.Type{
securityTypeHTTPBearer,
securityTypeHTTPBearerJWT,
securityTypeHTTPBasic,
securityTypeApiKey,
}
var typeFile = reflect.TypeOf(&multipart.FileHeader{})
var typeFiles = reflect.TypeOf([]*multipart.FileHeader{})
var typeCookie = reflect.TypeOf(&http.Cookie{})
var typeContext = reflect.TypeOf(&Context{})
var typeBytes = reflect.TypeOf([]byte{})
var interfaceIoReadCloser = reflect.TypeOf(new(io.ReadCloser)).Elem()
var typeAny = reflect.TypeOf(new(any)).Elem()