Documentation
¶
Overview ¶
Package s3 provides a source.Reader implementation that reads scripts from an Amazon S3 bucket (or any S3-compatible object storage such as MinIO, Alibaba OSS, Tencent COS, Cloudflare R2, LocalStack, ...).
Construction:
src, err := s3.New(ctx, "my-bucket",
s3.WithRegion("us-east-1"),
s3.WithPrefix("scripts/lua/"),
)
Hot-reload detection compares the object's ETag and LastModified against the values recorded by the most recent Load; a subsequent ReloadCheck reports true when either changes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("s3 source: object not found")
ErrNotFound is returned (wrapped) by Load / ReloadCheck when the requested object does not exist in the bucket. Detect with errors.Is(err, ErrNotFound) or the convenience helper IsNotFound.
Functions ¶
func IsNotFound ¶
IsNotFound reports whether err represents a "404 / NoSuchKey" response from S3. Equivalent to errors.Is(err, ErrNotFound).
Types ¶
type Option ¶
type Option func(*configOptions)
Option configures a [Source]. Pass to New.
func WithAnonymous ¶
func WithAnonymous() Option
WithAnonymous disables authentication entirely. Use for public buckets or for endpoints (such as test fakes) that don't validate signatures.
func WithCredentials ¶
func WithCredentials(p aws.CredentialsProvider) Option
WithCredentials supplies an explicit credentials provider. By default the standard AWS credential chain (env vars / shared config / IMDS / ECS) is used.
func WithEndpoint ¶
WithEndpoint overrides the AWS endpoint URL. Use this to point at MinIO, Alibaba OSS, Tencent COS, Cloudflare R2, LocalStack, etc.
func WithPathStyle ¶
func WithPathStyle() Option
WithPathStyle forces path-style addressing (https://endpoint/bucket/key instead of https://bucket.endpoint/key). Required by MinIO and some other self-hosted S3-compatible servers.
func WithPrefix ¶
WithPrefix sets a key prefix that is transparently prepended to every key before it is resolved against the bucket. Useful when all scripts share a common directory inside the bucket (e.g. WithPrefix("scripts/lua/")).
Leading slashes are stripped and a trailing slash is added automatically, so "scripts", "/scripts", "scripts/" all normalize to "scripts/".
func WithRegion ¶
WithRegion sets the AWS region (e.g. "us-east-1"). When omitted the default AWS SDK chain resolves the region from env / shared config.
func WithStaticCredentials ¶
WithStaticCredentials is a shortcut for WithCredentials with a static access-key / secret-key pair. Pass an empty token unless the credentials are temporary (STS).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads scripts from an S3 bucket.
All exported methods are safe for concurrent use. Reader implements the source.Reader interface.
func New ¶
New creates an S3-backed Reader. `bucket` is required; all other settings are optional.
Credentials are loaded via the default AWS SDK v2 chain (env vars / shared config / IMDS / ...). Override with WithCredentials / WithStaticCredentials / WithAnonymous.
For S3-compatible services pass WithEndpoint("https://...") and (typically) WithPathStyle().
func (*Reader) Close ¶
Close releases any underlying resources. The AWS SDK v2 S3 client has no explicit Close method, so this is currently a no-op; the method exists so Reader satisfies source.Reader and so future implementations can release resources (custom HTTP transports, pools, ...) here.
func (*Reader) Load ¶
Load fetches the object from S3 and returns its body as a string. Context cancellation propagates to the underlying request.
A "404 / NoSuchKey" response is reported as a wrapped ErrNotFound. Other errors are wrapped with the object key for easier debugging.
func (*Reader) Watch ¶
Watch returns a channel that signals when the object identified by `key` changes. It polls the object's ETag and LastModified via HeadObject every 5 seconds and sends a signal on the channel when either value changes.
The returned channel is closed when the context is cancelled. Callers should re-Load the script after receiving from the channel.