Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function to read version etag #411

Merged
merged 5 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dataset/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ type Temporal struct {
Frequency string `json:"frequency"`
}

// ResponseHedaers represents headers that are available in the HTTP response
type ResponseHeaders struct {
ETag string
}

// ToString builds a string of metadata information
func (m Metadata) ToString() string {
var b bytes.Buffer
Expand Down
19 changes: 16 additions & 3 deletions dataset/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,22 @@ func (c *Client) GetVersionsBatchProcess(ctx context.Context, userAuthToken, ser
}

// GetVersion gets a specific version for an edition from the dataset api
func (c *Client) GetVersion(ctx context.Context, userAuthToken, serviceAuthToken, downloadServiceAuthToken, collectionID, datasetID, edition, version string) (m Version, err error) {
func (c *Client) GetVersion(ctx context.Context, userAuthToken, serviceAuthToken, downloadServiceAuthToken, collectionID, datasetID, edition, version string) (v Version, err error) {
v, _, err = c.getVersion(ctx, userAuthToken, serviceAuthToken, downloadServiceAuthToken, collectionID, datasetID, edition, version)
return
}

// GetVersionWithHeaders gets a specific version for an edition from the dataset api and additional response headers
func (c *Client) GetVersionWithHeaders(ctx context.Context, userAuthToken, serviceAuthToken, downloadServiceAuthToken, collectionID, datasetID, edition, version string) (v Version, h ResponseHeaders, err error) {
v, resp, err := c.getVersion(ctx, userAuthToken, serviceAuthToken, downloadServiceAuthToken, collectionID, datasetID, edition, version)
h.ETag, _ = headers.GetResponseETag(resp)
return
}

func (c *Client) getVersion(ctx context.Context, userAuthToken, serviceAuthToken, downloadServiceAuthToken, collectionID, datasetID, edition, version string) (v Version, resp *http.Response, err error) {
uri := fmt.Sprintf("%s/datasets/%s/editions/%s/versions/%s", c.hcCli.URL, datasetID, edition, version)

resp, err := c.doGetWithAuthHeadersAndWithDownloadToken(ctx, userAuthToken, serviceAuthToken, downloadServiceAuthToken, collectionID, uri)
resp, err = c.doGetWithAuthHeadersAndWithDownloadToken(ctx, userAuthToken, serviceAuthToken, downloadServiceAuthToken, collectionID, uri)
if err != nil {
return
}
Expand All @@ -585,7 +597,8 @@ func (c *Client) GetVersion(ctx context.Context, userAuthToken, serviceAuthToken
return
}

err = json.Unmarshal(b, &m)
err = json.Unmarshal(b, &v)

return
}

Expand Down
Loading