Commit graph

9 commits

Author SHA1 Message Date
Winni Neessen a5667bb828
Add bearer token authentication
In this commit, we've added the capability to authenticate via bearer token to Meteologix's HTTP client. A new method "WithBearerToken" has been implemented, allowing a bearer token to be set in 'meteologix.go'. Additionally, in 'httpclient.go', the token is attached to the "Authorization" header for API requests. Tests asserting token setting functionality have been added in 'meteologix_test.go'. These changes open up an alternative authentication option for our API users. The bearer auth is not public yet, so there is no way for us to test this auth
2023-08-02 16:08:38 +02:00
Winni Neessen 3eb6a76f5d
Refactor HTTP client for improved error handling and readability
A few changes were made to `httpclient.go`. We swapped the `os` package for `log` to standardize error logging. Instead of having the HTTP transport as a value, it is now a pointer in the HTTP client instantiation function, aligning it with the client itself. We also altered error handling: we now just return an error when our server response is `nil`, and changed `sr.Body.Close()` error reporting to use `log` instead of `fmt`.

To streamline the code, user authentication function `setAuthHeader` was renamed to `setAuthentication`, and the copy of our HTTP response body to buffer now only happens after the status check. We also replaced the `Flush` error to be handled properly.

Successful requests return bytes instead of the buffer itself. As a result, these changes have led to more readable and effective code.
2023-06-27 18:31:13 +02:00
Winni Neessen a0b67b0367
Add client timeout and improve error handling
- Set HTTPClientTimeout for HTTP client to prevent hanging requests
- Check for http.StatusOK instead of a generic error-range
- Use json.NewDecoder to decode error JSON for better memory usage
2023-06-27 15:20:16 +02:00
Winni Neessen dec578e751
Added CODE_OF_CONDUCT.md, CONTRIBUTING.md and updated mail address in CopyrightText 2023-05-21 11:46:23 +02:00
Winni Neessen 7c9fae0671
More test coverage 2023-05-15 15:27:09 +02:00
Winni Neessen 923985102b
Implemented API error type 2023-05-14 15:55:03 +02:00
Winni Neessen 8441b60d15
Minor changes
- Non-negative HTTP response handling
- Renamed station method names and comments
2023-05-13 18:44:29 +02:00
Winni Neessen 50ad3747fc
Renamed some struct fields and added more test coverage 2023-05-13 13:18:47 +02:00
Winni Neessen 2ed373adf0
Initial checkin 2023-05-12 12:44:27 +02:00