diff options
author | 2024-08-06 17:16:35 -0700 | |
---|---|---|
committer | 2024-08-06 17:16:35 -0700 | |
commit | 961f9e0a76c3cfe9ae92ca8da0531790e0610b69 (patch) | |
tree | f6de4ed36c3f48ee94ecd524dedeb0d7c84b72e5 /backend/internal/ibd/userinfo.go | |
parent | 641c81198d7fed7138bb482f226e54bd703094ab (diff) | |
download | ibd-trader-961f9e0a76c3cfe9ae92ca8da0531790e0610b69.tar.gz ibd-trader-961f9e0a76c3cfe9ae92ca8da0531790e0610b69.tar.zst ibd-trader-961f9e0a76c3cfe9ae92ca8da0531790e0610b69.zip |
Modify IBD to accept various transport backends
This allows IBD to try using faster and cheaper transports first with
fallback to more reliable and expensive transports later.
Diffstat (limited to 'backend/internal/ibd/userinfo.go')
-rw-r--r-- | backend/internal/ibd/userinfo.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/backend/internal/ibd/userinfo.go b/backend/internal/ibd/userinfo.go index ba7a5b5..ed61497 100644 --- a/backend/internal/ibd/userinfo.go +++ b/backend/internal/ibd/userinfo.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "io" "log/slog" "net/http" ) @@ -24,17 +25,25 @@ func (c *Client) UserInfo(ctx context.Context, cookie *http.Cookie) (*UserProfil if err != nil { return nil, err } + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(resp.Body) - if resp.Result.StatusCode != http.StatusOK { + content, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("failed to read response body: %w", err) + } + + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf( "unexpected status code %d: %s", - resp.Result.StatusCode, - resp.Result.Content, + resp.StatusCode, + string(content), ) } up := new(UserProfile) - if err = up.UnmarshalJSON([]byte(resp.Result.Content)); err != nil { + if err = up.UnmarshalJSON(content); err != nil { return nil, err } |