request 统一请求接口
(url string, data interface{}, result interface{})
| 162 | |
| 163 | // request 统一请求接口 |
| 164 | func (pb *Porkbun) request(url string, data interface{}, result interface{}) (err error) { |
| 165 | jsonStr := make([]byte, 0) |
| 166 | if data != nil { |
| 167 | jsonStr, _ = json.Marshal(data) |
| 168 | } |
| 169 | req, err := http.NewRequest( |
| 170 | "POST", |
| 171 | url, |
| 172 | bytes.NewBuffer(jsonStr), |
| 173 | ) |
| 174 | if err != nil { |
| 175 | log.Println("http.NewRequest失败. Error: ", err) |
| 176 | return |
| 177 | } |
| 178 | req.Header.Set("Content-Type", "application/json") |
| 179 | |
| 180 | client, e := pb.CreateHTTPClient() |
| 181 | if e != nil { |
| 182 | err = e |
| 183 | return |
| 184 | } |
| 185 | |
| 186 | resp, err := client.Do(req) |
| 187 | if err != nil { |
| 188 | return err |
| 189 | } |
| 190 | |
| 191 | return httputils.GetAndParseJSONResponseFromHttpResponse(resp, result) |
| 192 | } |
no test coverage detected