stds3fx

package
v0.0.255 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stds3fx provides an S3 client (minio-go) and the buckets it may use, resolved from aliases so code never spells out a deployment's bucket names. The client speaks the S3 API to STDS3_ENDPOINT, which is AWS S3 by default and any S3-compatible server otherwise. With STDS3_ACCESS_KEY and STDS3_SECRET_KEY it signs with those; without them it finds credentials the way AWS SDKs do, from the environment, the shared credentials file, or the role of the EC2 instance, ECS task or Kubernetes service account.

Tests get isolated buckets the way they get isolated databases: with STDS3_CREATE_AND_USE_RANDOM_BUCKETS every configured bucket name gets a random suffix and is created when the fx application starts, and with STDS3_AUTO_REMOVE_BUCKETS it is emptied and deleted when it stops. stds3testfx sets both. Leave them unset elsewhere, where infrastructure owns the buckets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Provide

func Provide() fx.Option

Provide wires the module. It spells out what stdfx.ZapEnvCfgModule does, whose prefix for "stds3" would be STDS_3_.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the object storage client: the S3 client plus the resolved bucket names. It is safe for concurrent use.

func New

func New(params Params) (*Client, error)

New builds the client and, in random-bucket mode, ties bucket creation and removal to the application lifecycle.

func (*Client) Bucket

func (c *Client) Bucket(alias string) (string, bool)

Bucket returns the bucket name for an alias, such as "main". An alias that is not configured returns ok=false, which callers must treat as a programming error rather than fall back to another bucket.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping reports whether every configured bucket is reachable and exists, with a HeadBucket per bucket, all at once. It returns the first failure and stops the other checks. It only reads, so it is safe for the health check.

func (*Client) S3

func (c *Client) S3() *minio.Client

S3 returns the underlying S3 client for object operations; callers get bucket names from Client.Bucket.

type Config

type Config struct {
	// Buckets maps every bucket alias the code uses to the bucket name of the
	// environment, as alias:name pairs separated by commas.
	Buckets map[string]string `env:"BUCKETS,required"`
	// Endpoint is the URL of the S3 API, of AWS or an S3-compatible server. Its scheme
	// decides whether the client uses TLS.
	Endpoint string `env:"ENDPOINT" envDefault:"https://s3.amazonaws.com"`
	// Region is the region the client signs for. Setting it spares the client
	// a bucket location lookup; most S3-compatible servers accept any region.
	Region string `env:"REGION" envDefault:"us-east-1"`
	// AccessKey and SecretKey are static credentials, such as those of an
	// S3-compatible server. Without them the client uses the AWS credential
	// sources.
	AccessKey string `env:"ACCESS_KEY"`
	SecretKey string `env:"SECRET_KEY"`
	// CreateAndUseRandomBuckets suffixes every bucket name with a random hex
	// string and creates the buckets on start, so parallel tests against one
	// server do not see each other's objects.
	CreateAndUseRandomBuckets bool `env:"CREATE_AND_USE_RANDOM_BUCKETS"`
	// AutoRemoveBuckets empties and deletes the random buckets on stop.
	AutoRemoveBuckets bool `env:"AUTO_REMOVE_BUCKETS"`
}

Config is the env-driven configuration of the module (prefix STDS3_).

type Params

type Params struct {
	fx.In
	fx.Lifecycle

	Config Config
	Logs   *zap.Logger
}

Params is the fx input for New.

Directories

Path Synopsis
Package stds3testfx provides the stds3fx client for tests, on an S3 server that is started for the tests, so they need no Docker Compose or other prior setup.
Package stds3testfx provides the stds3fx client for tests, on an S3 server that is started for the tests, so they need no Docker Compose or other prior setup.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL