KubFly SDK for Go / bucket/s3
package s3
import "kubfly.io/sdk/bucket/s3"
Package s3 is S3 and S3-compatible clouds (Yandex, VK Cloud, Selectel, MinIO) as a bucket: one bucket, requests signed by AWS Signature Version 4, no dependencies but the standard library — the io.kubfly.sdk.bucket.s3 package of the Java SDK. Linking it in registers the kind S3 (KUBFLY_BUCKET_KIND=S3, KUBFLY_BUCKET_ENDPOINT, _REGION, _NAME, _ACCESS, _SECRET).
st, err := s3.NewBuilder().WithEndpoint("https://storage.yandexcloud.net").WithRegion("ru-central1").
WithName("kubfly").WithAccess(access).WithSecret(secret).Build()
Types
type Bucket
type Bucket struct {
// contains filtered or unexported fields
}
Bucket is a bucket of S3 by its REST API: HEAD, GET (with Range), PUT, DELETE of an object, ListObjectsV2 page by page; every request signed by AWS Signature Version 4 with the hash of its payload — a stream is read twice, to hash it and to send it. Failures that may pass are tried again (Builder.Attempts); every failure is a *bucket.Error with the code of S3. The Date of every response is the time of the bucket (Time). Safe for concurrent use.
func (*Bucket) Builder
func (s *Bucket) Builder() bucket.Builder
Builder are the settings.
func (*Bucket) Bytes
func (s *Bucket) Bytes(ctx context.Context, key string) (util.Option[bucket.Stored[[]byte]], error)
Bytes are the bytes of an object: GET.
func (*Bucket) BytesRange
func (s *Bucket) BytesRange(ctx context.Context, key string, offset int64, length int) (util.Option[bucket.Stored[[]byte]], error)
BytesRange is a range of the bytes of an object: GET with Range; fewer at its end.
func (*Bucket) Close
func (s *Bucket) Close() error
Close closes the idle connections.
func (*Bucket) Create
func (s *Bucket) Create(ctx context.Context, key string, data []byte) (bool, error)
Create writes an object only if there is none with the key: PUT with If-None-Match: *; 412 — there is one, 409 — another writer of the key is at it, so there will be one. An attempt the bucket took though its answer was lost is tried again and answered 412: the object is there either way.
func (*Bucket) Delete
func (s *Bucket) Delete(ctx context.Context, key string) error
Delete removes an object: DELETE; nothing happens if there is none.
func (*Bucket) Find
func (s *Bucket) Find(ctx context.Context, key string) (util.Option[bucket.Obj], error)
Find are the fields of an object: HEAD.
func (*Bucket) List
func (s *Bucket) List(ctx context.Context, prefix string) iter.Seq2[bucket.Obj, error]
List are the objects of a prefix, in the order of keys: ListObjectsV2, a page at a time as the iteration goes.
func (*Bucket) ListFilter
func (s *Bucket) ListFilter(ctx context.Context, prefix string, filter bucket.Filter) iter.Seq2[bucket.Obj, error]
ListFilter are the objects of a prefix that a filter takes.
func (*Bucket) Put
func (s *Bucket) Put(ctx context.Context, key string, data []byte) error
Put writes an object: PUT.
func (*Bucket) PutStream
func (s *Bucket) PutStream(ctx context.Context, key string, data func() (io.ReadCloser, error), length int64) error
PutStream writes an object from streams: one to hash it, one for every attempt to send it.
func (*Bucket) String
func (s *Bucket) String() string
String is the text form.
func (*Bucket) Time
func (s *Bucket) Time() util.Option[bucket.BucketTime]
Time is the time of the bucket by its last response with a Date.
type Builder
type Builder struct {
// contains filtered or unexported fields
}
Builder is S3 as a bucket (the kind S3) with its settings: the endpoint (http:// or https:// and a host, without a path), the region, the bucket, the keys, the style of addresses (the bucket in the path or in the host), the time to a response, the attempts (500, 502, 503, 504, RequestTimeout and failures of the network are tried again) from a pause that doubles, and the prefix of a stand. Settings are checked by Build.
func NewBuilder
func NewBuilder() Builder
NewBuilder is the kind S3 with its settings by default: the region us-east-1, the bucket in the path, 30 s to a response, 3 attempts from a pause of 100 ms.
func (Builder) Access
func (b Builder) Access() util.Option[string]
Access is the access key; None until it is set.
func (Builder) Attempts
func (b Builder) Attempts() int
Attempts is the attempts; 1 — no repeat.
func (Builder) Backoff
func (b Builder) Backoff() time.Duration
Backoff is the first pause between attempts.
func (Builder) Build
func (b Builder) Build() (bucket.Bucket, error)
Build checks the settings and connects; under the prefix of the stand, if any. Nothing is asked of the service yet: the first request shows whether it answers.
func (Builder) Endpoint
func (b Builder) Endpoint() util.Option[string]
Endpoint is the endpoint; None until it is set.
func (Builder) Env
func (b Builder) Env(envPrefix string, env map[string]string) (bucket.Builder, error)
Env is this builder filled from <ENV_PREFIX>_BUCKET_ENDPOINT, _REGION, _NAME, _ACCESS, _SECRET or _SECRET_FILE, _PATH_STYLE, _TIMEOUT (s), _ATTEMPTS, _BACKOFF (ms), _PREFIX; a variable not set keeps the setting.
func (Builder) GoString
func (b Builder) GoString() string
GoString is the text form of %#v, without the keys.
func (Builder) Kind
func (b Builder) Kind() string
Name is the name of the kind: S3.
func (Builder) Name
func (b Builder) Name() util.Option[string]
Name is the name of the bucket; None until it is set.
func (Builder) PathStyle
func (b Builder) PathStyle() bool
PathStyle is the style of addresses: true — the bucket in the path, false — in the host.
func (Builder) Prefix
func (b Builder) Prefix() string
Prefix is the prefix of the stand, "" — none.
func (Builder) Region
func (b Builder) Region() string
Region is the region.
func (Builder) Secret
func (b Builder) Secret() util.Option[string]
Secret is the secret key; None until it is set.
func (Builder) String
func (b Builder) String() string
String is the text form, without the keys.
func (Builder) Timeout
func (b Builder) Timeout() time.Duration
Timeout is the time to a response.
func (Builder) WithAccess
func (b Builder) WithAccess(access string) Builder
WithAccess is this builder with an access key.
func (Builder) WithAttempts
func (b Builder) WithAttempts(attempts int) Builder
WithAttempts is this builder with attempts; 1 — no repeat.
func (Builder) WithBackoff
func (b Builder) WithBackoff(backoff time.Duration) Builder
WithBackoff is this builder with the first pause between attempts.
func (Builder) WithEndpoint
func (b Builder) WithEndpoint(endpoint string) Builder
WithEndpoint is this builder with an endpoint; slashes at its end are dropped.
func (Builder) WithName
func (b Builder) WithName(name string) Builder
WithName is this builder with the name of the bucket.
func (Builder) WithPathStyle
func (b Builder) WithPathStyle(pathStyle bool) Builder
WithPathStyle is this builder with a style of addresses: true — the bucket in the path, false — in the host.
func (Builder) WithPrefix
func (b Builder) WithPrefix(prefix string) bucket.Builder
WithPrefix is this builder with the prefix of a stand ("" — none).
func (Builder) WithRegion
func (b Builder) WithRegion(region string) Builder
WithRegion is this builder with a region.
func (Builder) WithSecret
func (b Builder) WithSecret(secret string) Builder
WithSecret is this builder with a secret key.
func (Builder) WithTimeout
func (b Builder) WithTimeout(timeout time.Duration) Builder
WithTimeout is this builder with the time to a response.