@@ -27,33 +27,45 @@ func (r *JSONResponse) Bind(x interface{}) {
2727
2828func (r * JSON ) Get () * JSONResponse {
2929 req , _ := http .NewRequest ("GET" , r .URL , nil )
30- return r .perform (req )
30+ return r .Perform (req )
3131}
3232
3333func (r * JSON ) Delete () * JSONResponse {
3434 req , _ := http .NewRequest ("DELETE" , r .URL , nil )
35- return r .perform (req )
35+ return r .Perform (req )
3636}
3737
3838func (r * JSON ) Post (body interface {}) * JSONResponse {
3939 b , _ := json .Marshal (body )
4040 req , _ := http .NewRequest ("POST" , r .URL , bytes .NewReader (b ))
41- return r .perform (req )
41+ return r .Perform (req )
4242}
4343
4444func (r * JSON ) Put (body interface {}) * JSONResponse {
4545 b , _ := json .Marshal (body )
4646 req , _ := http .NewRequest ("PUT" , r .URL , bytes .NewReader (b ))
47- return r .perform (req )
47+ return r .Perform (req )
4848}
4949
5050func (r * JSON ) Patch (body interface {}) * JSONResponse {
5151 b , _ := json .Marshal (body )
5252 req , _ := http .NewRequest ("PATCH" , r .URL , bytes .NewReader (b ))
53- return r .perform (req )
53+ return r .Perform (req )
5454}
5555
56- func (r * JSON ) perform (req * http.Request ) * JSONResponse {
56+ func (r * JSON ) Do (method string , body interface {}) (* JSONResponse , error ) {
57+ b , err := json .Marshal (body )
58+ if err != nil {
59+ return nil , err
60+ }
61+ req , err := http .NewRequest (method , r .URL , bytes .NewReader (b ))
62+ if err != nil {
63+ return nil , err
64+ }
65+ return r .Perform (req ), nil
66+ }
67+
68+ func (r * JSON ) Perform (req * http.Request ) * JSONResponse {
5769 if r .handler .HmaxSecret != "" {
5870 hmax .SignRequest (req , []byte (r .handler .HmaxSecret ))
5971 }
0 commit comments