(pattern string, args ...interface{})
| 205 | } |
| 206 | |
| 207 | func getJSON(pattern string, args ...interface{}) (result *jsonq.JsonQuery, err error) { |
| 208 | url := "http://localhost:4663/" + apiProxyPrefix + "/" + fmt.Sprintf(pattern, args...) |
| 209 | resp, err := http.Get(url) |
| 210 | if err != nil { |
| 211 | return |
| 212 | } |
| 213 | |
| 214 | var res map[string]interface{} |
| 215 | err = json.NewDecoder(resp.Body).Decode(&res) |
| 216 | if err != nil { |
| 217 | return |
| 218 | } |
| 219 | log.WithFields(log.Fields{ |
| 220 | "pattern": pattern, |
| 221 | "args": args, |
| 222 | "response": res, |
| 223 | "code": resp.StatusCode, |
| 224 | }).Debug("send test request") |
| 225 | result = jsonq.NewQuery(res) |
| 226 | success, err := result.Bool("success") |
| 227 | if err != nil { |
| 228 | return |
| 229 | } |
| 230 | if !success { |
| 231 | var status string |
| 232 | status, err = result.String("status") |
| 233 | if err != nil { |
| 234 | return |
| 235 | } |
| 236 | err = errors.New(status) |
| 237 | return |
| 238 | } |
| 239 | result = jsonq.NewQuery(ensureSuccess(result.Interface("data"))) |
| 240 | |
| 241 | return |
| 242 | } |
| 243 | |
| 244 | func ensureSuccess(v interface{}, err error) interface{} { |
| 245 | if err != nil { |
no test coverage detected