gin icon indicating copy to clipboard operation
gin copied to clipboard

binding: support []byte

Open guonaihong opened this issue 4 years ago • 3 comments

env GOPATH=`pwd` go run form1.go
  • form1.go
package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

type testForm struct {
	Mode   string `form:"mode"`
	Text   string `form:"text"`
	Voice  []byte `form:"voice"`
	Voice2 []byte `form:"voice2"`
}

func main() {
	router := gin.Default()
	router.POST("/test.form", func(c *gin.Context) {

		t2 := testForm{}
		if err := c.ShouldBind(&t2); err != nil {
			fmt.Printf("err = %s:%v\n", err, t2)
			c.JSON(500, gin.H{"err": err.Error()})
			return
		}
		c.JSON(200, t2)
	})

	router.Run()
}

//client
/*
curl -F mode=A -F text="test" -F [email protected] -F voice2="voice" 127.0.0.1:8080/test.form|jq
{
  "Mode": "A",
  "Text": "test",
  "Voice": "cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImZtdCIKCSJnaXRodWIuY29tL2dpbi1nb25pYy9naW4iCikKCnR5cGUgdGVzdEZvcm0gc3RydWN0IHsKCU1vZGUgICBzdHJpbmcgYGZvcm06Im1vZGUiYAoJVGV4dCAgIHN0cmluZyBgZm9ybToidGV4dCJgCglWb2ljZSAgW11ieXRlIGBmb3JtOiJ2b2ljZSJgCglWb2ljZTIgW11ieXRlIGBmb3JtOiJ2b2ljZTIiYAp9CgpmdW5jIG1haW4oKSB7Cglyb3V0ZXIgOj0gZ2luLkRlZmF1bHQoKQoJcm91dGVyLlBPU1QoIi90ZXN0LmZvcm0iLCBmdW5jKGMgKmdpbi5Db250ZXh0KSB7CgoJCXQyIDo9IHRlc3RGb3Jte30KCQlpZiBlcnIgOj0gYy5TaG91bGRCaW5kKCZ0Mik7IGVyciAhPSBuaWwgewoJCQlmbXQuUHJpbnRmKCJlcnIgPSAlczoldlxuIiwgZXJyLCB0MikKCQkJYy5KU09OKDUwMCwgZ2luLkh7ImVyciI6IGVyci5FcnJvcigpfSkKCQkJcmV0dXJuCgkJfQoJCWMuSlNPTigyMDAsIHQyKQoJfSkKCglyb3V0ZXIuUnVuKCkKfQo=",
  "Voice2": "dm9pY2U="
}
*/

guonaihong avatar Aug 13 '19 13:08 guonaihong

Codecov Report

Merging #2015 into master will decrease coverage by 0.07%. The diff coverage is 87.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2015      +/-   ##
==========================================
- Coverage   98.69%   98.61%   -0.08%     
==========================================
  Files          40       40              
  Lines        2225     2241      +16     
==========================================
+ Hits         2196     2210      +14     
- Misses         16       17       +1     
- Partials       13       14       +1
Impacted Files Coverage Δ
binding/form_mapping.go 100% <100%> (ø) :arrow_up:
binding/multipart_form_mapping.go 95.55% <81.81%> (-4.45%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 5612cad...24943ac. Read the comment docs.

codecov[bot] avatar Aug 13 '19 13:08 codecov[bot]

Please fix the conflicts and move to 1.11

appleboy avatar Mar 21 '24 14:03 appleboy

Okay, I'll set aside time on Saturday to fix it.

guonaihong avatar Mar 21 '24 15:03 guonaihong