MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / getJSON

Function getJSON

sqlchain/observer/observation_test.go:207–242  ·  view source on GitHub ↗
(pattern string, args ...interface{})

Source from the content-addressed store, hash-verified

205}
206
207func 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
244func ensureSuccess(v interface{}, err error) interface{} {
245 if err != nil {

Callers 1

TestFullProcessFunction · 0.85

Calls 6

WithFieldsFunction · 0.92
ensureSuccessFunction · 0.85
DebugMethod · 0.80
GetMethod · 0.65
NewMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected