File tree 1 file changed +17
-5
lines changed
1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -190,13 +190,11 @@ func (c *Context) ClientIP() string {
190
190
// It decodes the json payload into the struct specified as a pointer.
191
191
// Like ParseBody() but this method also writes a 400 error if the json is not valid.
192
192
func (c * Context ) Bind (data BindingStruct ) error {
193
- err := data . Validate ( )
194
- if err != nil {
193
+ binding := bindDefault ( c . Request . Method , c . ContentType () )
194
+ if err := binding . Bind ( c . Request , data ); err != nil {
195
195
return err
196
196
}
197
-
198
- binding := bindDefault (c .Request .Method , c .ContentType ())
199
- return binding .Bind (c .Request , data )
197
+ return data .Validate ()
200
198
}
201
199
202
200
// WriteHeader sends an HTTP response header with status code.
@@ -307,6 +305,20 @@ func (c *Context) SetResult(code int, msg string) {
307
305
}
308
306
}
309
307
308
+ // SetBody return json body
309
+ func (c * Context ) SetBody (data interface {}) {
310
+ rsp := map [string ]interface {}{
311
+ "code" : 0 ,
312
+ "msg" : "ok" ,
313
+ "data" : data ,
314
+ }
315
+
316
+ if err := renderJSON (c .ResponseWriter , rsp ); err != nil {
317
+ panic (err )
318
+ }
319
+ }
320
+
321
+ // HTML rendder html resp
310
322
func (c * Context ) HTML (name string , data interface {}) {
311
323
if err := renderHTML (c .ResponseWriter , c .template , name , data ); err != nil {
312
324
panic (err )
You can’t perform that action at this time.
0 commit comments