go.bigb.es/cacher @ v0.1.2 — 9dc739e5 2 months ago
import "go.bigb.es/cacher/internal/s3"
type Client struct { // contains filtered or unexported fields }
Client is a small surface over the S3 SDK tuned for the cacher use case.
New constructs a Client. The HTTP client uses Go's default transport; callers can decorate later if needed (timeouts, proxies).
func (c *Client) Bucket() string
Bucket returns the configured bucket name (for diagnostics).
func (c *Client) Delete(ctx context.Context, key string) error
Delete removes the object. Deleting a missing object returns nil (matches `aws s3 rm` semantics).
func (c *Client) Exists(ctx context.Context, key string) (bool, error)
Exists returns true if the object is present.
func (c *Client) FullKey(key string) string
FullKey returns prefix/key, with single-slash semantics.
func (c *Client) Get(ctx context.Context, key string) (io.ReadCloser, error)
Get streams the object body. Caller must Close the returned reader.
func (c *Client) List(ctx context.Context, sub string, recursive bool) (ListResult, error)
List walks objects under sub. When recursive is false, results are delimited by "/" so output matches `aws s3 ls` — common prefixes surface as "directories".
func (c *Client) PingBucket(ctx context.Context) error
PingBucket is the smoke test used by `cacher doctor`. Garage rejects HeadBucket with 403 even for valid credentials, so we use a 1-key ListObjectsV2 instead — matches `aws s3 ls s3://$bucket/` from the shell helper this replaces.
func (c *Client) Put(ctx context.Context, key string, body io.Reader) error
Put uploads body to key, streaming. Multipart is automatic for bodies over the manager's PartSize threshold (5MiB by default).
type ListResult struct { Keys []string // object keys relative to the client prefix Prefixes []string // common prefixes (each ending in "/") relative to the client prefix }
ListResult separates "files at this level" from "common prefixes (directories)". When recursive=true, Prefixes is always empty and Keys contains every object under sub.
Package s3 wraps the AWS SDK v2 S3 client with the Garage-compatible settings that the existing .builds/lib/ci-lib.sh shell helpers configure via ~/.aws/config: