git.iko.soy/typeable/oauth2-proxy
on 59c3ba4 help sign in
32 lines 623 B history raw
1package api
3import (
4 "errors"
5 "io/ioutil"
6 "log"
7 "net/http"
9 "github.com/bitly/go-simplejson"
12func Request(req *http.Request) (*simplejson.Json, error) {
13 httpclient := &http.Client{}
14 resp, err := httpclient.Do(req)
15 if err != nil {
16 return nil, err
17 }
18 body, err := ioutil.ReadAll(resp.Body)
19 resp.Body.Close()
20 if err != nil {
21 return nil, err
22 }
23 if resp.StatusCode != 200 {
24 log.Printf("got response code %d - %s", resp.StatusCode, body)
25 return nil, errors.New("api request returned non 200 status code")
26 }
27 data, err := simplejson.NewJson(body)
28 if err != nil {
29 return nil, err
30 }
31 return data, nil