Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom BindWith error managing #662

Open
javierprovecho opened this issue Jul 13, 2016 · 6 comments
Open

Custom BindWith error managing #662

javierprovecho opened this issue Jul 13, 2016 · 6 comments
Assignees

Comments

@javierprovecho
Copy link
Member

Hello @danslimmon, @DennyLoko, @sidbusy, @stxml, @dgsi, @kongfei605, @LeBronoMars and @tsirolnik,

First of all, sorry for delay in answering, I was just a little bit busy with university (final exams).

Regarding all the following issues (#629, #633, #636, danslimmon#1 and #661), here is what I suggest:

Because I'm not a native english speaker, maybe the naming of the two new proposed functions sound strange or completely wrong, so I'm open to suggestion about this, and also about everything else in this message.

Hope I did explained correctly. Tell me your thoughts.

@sidbusy
Copy link

sidbusy commented Jul 13, 2016

Looks good, before these, I can use binding.FormPost.Bind() instead.

@DennyLoko
Copy link

Hello @javierprovecho,

These modifications LGTM. Do you need any help on them ?

@javierprovecho
Copy link
Member Author

I'll get back on this tomorrow

@ghost
Copy link

ghost commented Nov 21, 2016

What's the status on this? Really cramping my error style.

@appleboy
Copy link
Member

@javierprovecho already merged #855 to develop branch so now we can use c.ShouldBindWith() which will allow custom error management.

@18959263172
Copy link

a little question.

func (jsonBinding) Bind(req *http.Request, obj interface{}) error {
	log.Println("binding called")
	b := make([]byte,req.ContentLength)
	log.Println("data",req.ContentLength)
	log.Println(req.Body)

	n,e := io.Reader(req.Body).Read(b)
	if e != nil{
		log.Println("read err ",e.Error(),n)
		return  e
	}
	log.Println(string(b))

	e = gjson.Unmarshal(b,obj)
	if e != nil{
		log.Println("error unmarlshal json",e.Error())
		return e
	}
	return nil

}

some wrong when invoke n,e := io.Reader(req.Body).Read(b)
the error just return EOF,any idea???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants