package heliumapi import ( "fmt" "io/ioutil" "net/http" ) const ( apiUrl = "https://api.helium.io" ) var ( client = &http.Client{} ) func getHeliumApi(path string, params *map[string]string) ([]byte, error) { req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s", apiUrl, path), nil) // setup headers req.Header.Add("Accept", "application/json") // setup query param if there are any if params != nil { query := req.URL.Query() for k, v := range *params { query.Add(k, v) } if err != nil { return nil, err } req.URL.RawQuery = query.Encode() } // query the api resp, err := client.Do(req) if err != nil { return nil, fmt.Errorf("failed to query path %v: %v", path, err) } defer resp.Body.Close() // read the response body body, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read response body of path %v: %v", path, err) } return body, nil } func getHeliumApiWithCursor(path string, params *map[string]string) ([]byte, error) { return nil, nil }