-
Notifications
You must be signed in to change notification settings - Fork 42
/
parameters.go
59 lines (53 loc) · 1.16 KB
/
parameters.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
package importer
type Param struct {
Field
In string
}
type Parameters struct {
items map[string]Param
insertOrder []string
}
func (p *Parameters) Add(param Param) {
if p.items == nil {
p.items = map[string]Param{}
}
if _, found := p.items[param.Name]; !found {
p.insertOrder = append(p.insertOrder, param.Name)
}
p.items[param.Name] = param
}
func (p *Parameters) Extend(others Parameters) Parameters {
res := Parameters{}
for _, name := range p.insertOrder {
res.Add(p.items[name])
}
for _, name := range others.insertOrder {
res.Add(others.items[name])
}
return res
}
func (p Parameters) findParams(where string) []Param {
var res []Param
for _, name := range p.insertOrder {
item := p.items[name]
if item.In == where {
res = append(res, item)
}
}
return res
}
func (p Parameters) QueryParams() []Param {
return p.findParams("query")
}
func (p Parameters) HeaderParams() []Param {
return p.findParams("header")
}
func (p Parameters) BodyParams() []Param {
return p.findParams("body")
}
func (p Parameters) PathParams() []Param {
return p.findParams("path")
}
func (p Parameters) CookieParams() []Param {
return p.findParams("cookie")
}