add sunnah api (#210)

This commit is contained in:
Asim Aslam
2021-09-21 15:19:22 +01:00
committed by GitHub
parent 45c7f5b0bf
commit 6e40bfe06a
15 changed files with 2122 additions and 1 deletions

View File

@@ -8,8 +8,27 @@ import (
"net/http"
)
var (
keys = map[string]string{}
)
// Set a key within the header
func SetKey(k, v string) {
keys[k] = v
}
// Get a url and unmarshal a json body into the given value
func Get(url string, rsp interface{}) error {
resp, err := http.Get(url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
for k, v := range keys {
req.Header.Set(k, v)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}