aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md8
-rw-r--r--account.go8
-rw-r--r--bulk.go4
-rw-r--r--largeobject.go2
-rw-r--r--object.go8
-rw-r--r--object_test.go5
6 files changed, 22 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ecd4d6..ac705b1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,11 @@
+# v2.0.0 (TBD)
+
+Breaking changes:
+
+- All methods that make HTTP requests now take a leading `context.Context` argument.
+ The `RequestOptions.Context` field has been removed because it is made redundant
+ by these extra arguments.
+
# v1.3.0 (2023-10-25)
New features:
diff --git a/account.go b/account.go
index 3b37b17..cfc5b31 100644
--- a/account.go
+++ b/account.go
@@ -189,7 +189,7 @@ func (a *Account) Containers() *ContainerIterator {
// Capabilities queries the GET /info endpoint of the Swift server providing
// this account. Capabilities are cached, so the GET request will only be sent
// once during the first call to this method.
-func (a *Account) Capabilities() (Capabilities, error) {
+func (a *Account) Capabilities(ctx context.Context) (Capabilities, error) {
a.capsMutex.Lock()
defer a.capsMutex.Unlock()
@@ -197,7 +197,7 @@ func (a *Account) Capabilities() (Capabilities, error) {
return *a.caps, nil
}
- buf, err := a.RawCapabilities()
+ buf, err := a.RawCapabilities(ctx)
if err != nil {
return Capabilities{}, err
}
@@ -215,10 +215,10 @@ func (a *Account) Capabilities() (Capabilities, error) {
// RawCapabilities queries the GET /info endpoint of the Swift server providing
// this account, and returns the response body. Unlike Account.Capabilities,
// this method does not employ any caching.
-func (a *Account) RawCapabilities() ([]byte, error) {
+func (a *Account) RawCapabilities(ctx context.Context) ([]byte, error) {
// This method is the only one in Schwift that bypasses struct Request since
// the request URL is not below the endpoint URL.
- req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, a.baseURL+"info", http.NoBody)
+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, a.baseURL+"info", http.NoBody)
if err != nil {
return nil, err
}
diff --git a/bulk.go b/bulk.go
index f345345..7115b26 100644
--- a/bulk.go
+++ b/bulk.go
@@ -67,7 +67,7 @@ const (
// This operation returns (0, ErrNotSupported) if the server does not support
// bulk-uploading.
func (a *Account) BulkUpload(ctx context.Context, uploadPath string, format BulkUploadFormat, contents io.Reader, opts *RequestOptions) (int, error) {
- caps, err := a.Capabilities()
+ caps, err := a.Capabilities(ctx)
if err != nil {
return 0, err
}
@@ -158,7 +158,7 @@ func (a *Account) BulkDelete(ctx context.Context, objects []*Object, containers
}
// check capabilities to choose deletion method
- caps, err := a.Capabilities()
+ caps, err := a.Capabilities(ctx)
if err != nil {
return 0, 0, err
}
diff --git a/largeobject.go b/largeobject.go
index e77779b..2ce63a8 100644
--- a/largeobject.go
+++ b/largeobject.go
@@ -667,7 +667,7 @@ func (lo *LargeObject) Append(ctx context.Context, contents io.Reader, segmentSi
}
if segmentSizeBytes == 0 {
// apply default value for segmenting size
- caps, err := lo.object.c.a.Capabilities()
+ caps, err := lo.object.c.a.Capabilities(ctx)
if err != nil {
return err
}
diff --git a/object.go b/object.go
index 1658273..28c33da 100644
--- a/object.go
+++ b/object.go
@@ -647,13 +647,13 @@ func contains(s []string, e string) bool {
// hdr := NewContainerHeaders()
// hdr.TempURLKey().Set(key)
// c := o.Container()
-// err := c.Update(hdr, nil)
+// err := c.Update(ctx, hdr, nil)
//
// //...we can use it to generate temporary URLs.
-// url := o.TempURL(key, "GET", time.Now().Add(10 * time.Minute))
+// url := o.TempURL(ctx, key, "GET", time.Now().Add(10 * time.Minute))
// resp, err := http.Get(url)
// //This time, resp.StatusCode == 200 because the URL includes a token.
-func (o *Object) TempURL(key, method string, expires time.Time) (string, error) {
+func (o *Object) TempURL(ctx context.Context, key, method string, expires time.Time) (string, error) {
urlStr, err := o.URL()
if err != nil {
return "", err
@@ -663,7 +663,7 @@ func (o *Object) TempURL(key, method string, expires time.Time) (string, error)
return "", err
}
- capabilities, err := o.c.a.Capabilities()
+ capabilities, err := o.c.a.Capabilities(ctx)
if err != nil {
return "", err
}
diff --git a/object_test.go b/object_test.go
index e5ad385..e614174 100644
--- a/object_test.go
+++ b/object_test.go
@@ -19,6 +19,7 @@
package schwift
import (
+ "context"
"io"
"net/http"
"strings"
@@ -66,7 +67,7 @@ func TestObjectTempURLSha1Only(t *testing.T) {
})
must(t, err)
- actualURL, err := account.Container("foo").Object("bar").TempURL("supersecretkey", "GET", time.Unix(1e9, 0))
+ actualURL, err := account.Container("foo").Object("bar").TempURL(context.TODO(), "supersecretkey", "GET", time.Unix(1e9, 0))
must(t, err)
expectedURL := "https://example.com/v1/AUTH_example/foo/bar?temp_url_sig=ed44d92005345aee463c884d76d4850ef6d2778d&temp_url_expires=1000000000"
@@ -81,7 +82,7 @@ func TestObjectTempURL(t *testing.T) {
})
must(t, err)
- actualURL, err := account.Container("foo").Object("bar").TempURL("supersecretkey", "GET", time.Unix(1e9, 0))
+ actualURL, err := account.Container("foo").Object("bar").TempURL(context.TODO(), "supersecretkey", "GET", time.Unix(1e9, 0))
must(t, err)
expectedURL := "https://example.com/v1/AUTH_example/foo/bar?temp_url_sig=5fc94a988b502d83e88863774812636ef0133b8aae04b20366fd906bff41189f&temp_url_expires=1000000000"