diff options
| author | Paul Buetow <paul@buetow.org> | 2024-05-16 00:27:56 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-05-16 00:27:56 +0300 |
| commit | 4057c17487a6713adccad61da8a3a58a0863db37 (patch) | |
| tree | a9c76042095d9a7fd1ed9a6c0bbd9e31ae2f57ae /internal/easyhttp | |
| parent | 51ebb1e131818f9b23dd25dea5be841a90476d50 (diff) | |
more on merge support
Diffstat (limited to 'internal/easyhttp')
| -rw-r--r-- | internal/easyhttp/easyhttp.go | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/internal/easyhttp/easyhttp.go b/internal/easyhttp/easyhttp.go index aa405e6..7cd24ff 100644 --- a/internal/easyhttp/easyhttp.go +++ b/internal/easyhttp/easyhttp.go @@ -1,6 +1,7 @@ package easyhttp import ( + "fmt" "io" "net/http" "encoding/json" @@ -14,33 +15,31 @@ func Get(uri, apiKey string) ([]byte, error) { req, err := http.NewRequest("GET", uri, nil) if err != nil { - return bytes, err - } + return bytes, fmt.Errorf("%s: %w", uri, err) + } req.Header.Set("X-API-KEY", apiKey) resp, err := client.Do(req) if err != nil { - return bytes, err + return bytes, fmt.Errorf("%s: %w", uri, err) } defer resp.Body.Close() bytes, err = io.ReadAll(resp.Body) if err != nil { - return bytes, err + return bytes, fmt.Errorf("%s: %w", uri, err) } return bytes, nil } -func GetFromJson[T any](uri, apiKey string) (T, error) { - var data T - +// Get data from JSON +func GetData[T any](uri, apiKey string, data *T) error { bytes, err := Get(uri, apiKey) if err != nil { - return data, err + return err } - err = json.Unmarshal(bytes, &data) - return data, err + return json.Unmarshal(bytes, data) } |
