瀏覽代碼

Improves Context.Input

Manu Mtz-Almeida 10 年之前
父節點
當前提交
5ee822fcee
共有 1 個文件被更改,包括 6 次插入8 次删除
  1. 6 8
      input_holder.go

+ 6 - 8
input_holder.go

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