Improves Context.Input

This commit is contained in:
Manu Mtz-Almeida 2015-04-07 23:28:49 +02:00
parent 1532be7c10
commit 5ee822fcee
1 changed files with 6 additions and 8 deletions

View File

@ -19,10 +19,10 @@ func (i inputHolder) FromPOST(key string) (va string) {
}
func (i inputHolder) Get(key string) string {
if value, exists := i.fromGET(key); exists {
if value, exists := i.fromPOST(key); exists {
return value
}
if value, exists := i.fromPOST(key); exists {
if value, exists := i.fromGET(key); exists {
return value
}
return ""
@ -31,19 +31,17 @@ func (i inputHolder) Get(key string) string {
func (i inputHolder) fromGET(key string) (string, bool) {
req := i.context.Request
req.ParseForm()
if values, ok := req.Form[key]; ok {
if values, ok := req.Form[key]; ok && len(values) > 0 {
return values[0], true
} else {
return "", false
}
return "", false
}
func (i inputHolder) fromPOST(key string) (string, bool) {
req := i.context.Request
req.ParseForm()
if values, ok := req.PostForm[key]; ok {
if values, ok := req.PostForm[key]; ok && len(values) > 0 {
return values[0], true
} else {
return "", false
}
return "", false
}