Do a request
(method string, data interface{})
| 169 | |
| 170 | // Do a request |
| 171 | func (req *Request) Do(method string, data interface{}) (*Response, error) { |
| 172 | req.method = method |
| 173 | |
| 174 | switch method { |
| 175 | case http.MethodGet, http.MethodDelete: |
| 176 | if data != nil { |
| 177 | if params, ok := data.(map[string]interface{}); ok { //nolint |
| 178 | req.SetParams(params) |
| 179 | } else { |
| 180 | req.err = errors.New("params is not a map[string]interface{}") |
| 181 | return nil, req.err |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | return req.pull() |
| 186 | |
| 187 | case http.MethodPost, http.MethodPut, http.MethodPatch: |
| 188 | if data != nil { |
| 189 | req.SetBody(data) |
| 190 | } |
| 191 | |
| 192 | return req.push() |
| 193 | } |
| 194 | |
| 195 | req.err = errors.New("unknow method " + method) |
| 196 | return nil, req.err |
| 197 | } |
| 198 | |
| 199 | func (req *Request) pull() (*Response, error) { |
| 200 | val := "" |