1
0
Fork 0
This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
helium-blockchain-exporter/heliumapi/query.go

54 lines
1.0 KiB
Go
Raw Normal View History

2021-09-13 03:25:47 +00:00
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
}