forked from gin-gonic/gin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_holder.go
49 lines (42 loc) · 1001 Bytes
/
input_holder.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
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package gin
type inputHolder struct {
context *Context
}
func (i inputHolder) FromGET(key string) (va string) {
va, _ = i.fromGET(key)
return
}
func (i inputHolder) FromPOST(key string) (va string) {
va, _ = i.fromPOST(key)
return
}
func (i inputHolder) Get(key string) string {
if value, exists := i.fromGET(key); exists {
return value
}
if value, exists := i.fromPOST(key); exists {
return value
}
return ""
}
func (i inputHolder) fromGET(key string) (string, bool) {
req := i.context.Request
req.ParseForm()
if values, ok := req.Form[key]; ok {
return values[0], true
} else {
return "", false
}
}
func (i inputHolder) fromPOST(key string) (string, bool) {
req := i.context.Request
req.ParseForm()
if values, ok := req.PostForm[key]; ok {
return values[0], true
} else {
return "", false
}
}