-
Notifications
You must be signed in to change notification settings - Fork 4
/
args.go
35 lines (30 loc) · 910 Bytes
/
args.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
// Content managed by Project Forge, see [projectforge.md] for details.
package cutil
import (
"github.com/valyala/fasthttp"
)
type Arg struct {
Key string `json:"key"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Default string `json:"default,omitempty"`
}
type Args []*Arg
type ArgResults struct {
Args Args `json:"args"`
Values map[string]string `json:"values"`
Missing []string `json:"missing,omitempty"`
}
func CollectArgs(rc *fasthttp.RequestCtx, args Args) *ArgResults {
ret := make(map[string]string, len(args))
var missing []string
for _, arg := range args {
qa := rc.URI().QueryArgs()
if !qa.Has(arg.Key) {
missing = append(missing, arg.Key)
}
ret[arg.Key] = string(qa.Peek(arg.Key))
}
return &ArgResults{Args: args, Values: ret, Missing: missing}
}