client

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetaStoreName     = "mp_meta"
	PartMetaStoreName = "mp_part_meta"
	TempStoreName     = "mp_temp"
)

Variables

View Source
var ErrBucketAlreadyExists = errors.New("bucket already exists")
View Source
var ErrBucketNotFound = errors.New("bucket not found")
View Source
var ErrMissingPart = errors.New("missing part")
View Source
var ErrObjectNotFound = errors.New("object not found")
View Source
var ErrUploadCompleted = errors.New("completed multipart upload")
View Source
var ErrUploadNotFound = errors.New("multipart upload not found")

Functions

This section is empty.

Types

type Client

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

Client wraps a NATS connection and metadata used by gateway components.

func NewClient

func NewClient(kind string) *Client

NewClient creates a new Client with a generated ID and the provided kind used in connection names and logs.

func (*Client) Close added in v0.4.1

func (c *Client) Close()

Close closes the NATS connection.

func (*Client) ID

func (c *Client) ID() string

ID returns the client's stable unique identifier.

func (*Client) Jetstream added in v0.4.0

func (c *Client) Jetstream() (jetstream.JetStream, error)

JetStream a new JetStream instance.

func (*Client) NATS

func (c *Client) NATS() *nats.Conn

NATS returns the underlying NATS connection.

func (*Client) Name

func (c *Client) Name() string

Name returns a human-readable connection name used for NATS.

func (*Client) SetupConnectionToNATS

func (c *Client) SetupConnectionToNATS(servers string, options ...nats.Option) error

SetupConnectionToNATS establishes a connection to the given NATS servers applying the provided options and sets standard event handlers.

type MetricCollector added in v0.3.1

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

func NewMetricCollector added in v0.3.1

func NewMetricCollector(logger log.Logger, client *NatsObjectClient) *MetricCollector

func (MetricCollector) Collect added in v0.3.1

func (c MetricCollector) Collect(ch chan<- prometheus.Metric)

Collect implements the prometheus.Collector interface.

func (MetricCollector) Describe added in v0.3.1

func (c MetricCollector) Describe(ch chan<- *prometheus.Desc)

Describe implements the prometheus.Collector interface.

type MultiPartStore added in v0.3.1

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

MultiPartStore groups storage backends used for multipart uploads. metaStore tracks session metadata in a Key-Value bucket, while tempPartStore holds uploaded parts in a temporary Object Store.

func NewMultiPartStore added in v0.3.2

func NewMultiPartStore(logger log.Logger, c *Client) (*MultiPartStore, error)

func (*MultiPartStore) AbortMultipartUpload added in v0.3.2

func (m *MultiPartStore) AbortMultipartUpload(ctx context.Context, bucket string, key string, uploadID string) error

AbortMultipartUpload aborts an in‑progress multipart upload, deleting any uploaded parts and removing the session metadata.

func (*MultiPartStore) CompleteMultipartUpload added in v0.3.2

func (m *MultiPartStore) CompleteMultipartUpload(ctx context.Context, bucket string, key string, uploadID string, sortedPartNumbers []int) (string, error)

CompleteMultipartUpload concatenates the uploaded parts into the final object, computes and returns the multipart ETag, and cleans up temporary parts and metadata.

func (*MultiPartStore) InitMultipartUpload added in v0.3.2

func (m *MultiPartStore) InitMultipartUpload(ctx context.Context, bucket string, key string, uploadID string) error

InitMultipartUpload creates and persists a new multipart upload session for the given bucket/key and uploadID.

func (*MultiPartStore) ListParts added in v0.3.2

func (m *MultiPartStore) ListParts(ctx context.Context, bucket string, key string, uploadID string) (*UploadMeta, error)

ListParts returns the multipart upload metadata for the given bucket/key/uploadID, including uploaded parts with sizes and ETags.

func (*MultiPartStore) UploadPart added in v0.3.2

func (m *MultiPartStore) UploadPart(ctx context.Context, bucket string, key string, uploadID string, part int, dataReader io.ReadCloser) (string, error)

UploadPart streams a part into temporary storage and records its ETag/size under the multipart session. Returns the hex ETag (without quotes).

type NatsObjectClient

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

NatsObjectClient provides convenience helpers for common NATS JetStream Object Store operations, built on top of the base Client connection.

func NewNatsObjectClient added in v0.3.1

func NewNatsObjectClient(logger log.Logger,
	natsClient *Client,
	opts NatsObjectClientOptions) (*NatsObjectClient, error)

func (*NatsObjectClient) Close added in v0.4.1

func (c *NatsObjectClient) Close()

Close closes the underlying NATS connection.

func (*NatsObjectClient) CreateBucket

func (c *NatsObjectClient) CreateBucket(ctx context.Context, bucketName string) (jetstream.ObjectStoreStatus, error)

CreateBucket creates a JetStream Object Store bucket.

func (*NatsObjectClient) DeleteBucket

func (c *NatsObjectClient) DeleteBucket(ctx context.Context, bucket string) error

DeleteBucket deletes a bucket identified by its name.

func (*NatsObjectClient) DeleteObject

func (c *NatsObjectClient) DeleteObject(ctx context.Context, bucket string, key string) error

DeleteObject removes an object identified by bucket and key.

func (*NatsObjectClient) DeleteObjectTags added in v0.4.0

func (c *NatsObjectClient) DeleteObjectTags(ctx context.Context, bucket string, key string) error

DeleteObjectTags removes all tags from an object.

func (*NatsObjectClient) GetObject

func (c *NatsObjectClient) GetObject(ctx context.Context, bucket string, key string) (*jetstream.ObjectInfo, []byte, error)

GetObject retrieves an object's metadata and bytes.

func (*NatsObjectClient) GetObjectInfo

func (c *NatsObjectClient) GetObjectInfo(ctx context.Context, bucket string, key string) (*jetstream.ObjectInfo, error)

GetObjectInfo fetches metadata for an object.

func (*NatsObjectClient) GetObjectRetention added in v0.3.3

func (c *NatsObjectClient) GetObjectRetention(ctx context.Context, bucket string, key string) (mode string, retainUntilDate string, err error)

GetObjectRetention retrieves retention metadata for an object

func (*NatsObjectClient) IsConnected added in v0.3.1

func (c *NatsObjectClient) IsConnected() bool

IsConnected checks if NATS is connected

func (*NatsObjectClient) ListBuckets

func (c *NatsObjectClient) ListBuckets(ctx context.Context) (<-chan jetstream.ObjectStoreStatus, error)

ListBuckets returns a channel of object store statuses for all buckets.

func (*NatsObjectClient) ListObjects

func (c *NatsObjectClient) ListObjects(ctx context.Context, bucket string) ([]*jetstream.ObjectInfo, error)

ListObjects lists all objects in the given bucket.

func (*NatsObjectClient) PutObjectRetention added in v0.3.3

func (c *NatsObjectClient) PutObjectRetention(ctx context.Context, bucket string, key string, mode string, retainUntilDate string) error

PutObjectRetention sets retention metadata for an existing object

func (*NatsObjectClient) PutObjectStream added in v0.3.10

func (c *NatsObjectClient) PutObjectStream(ctx context.Context,
	bucket string,
	key string,
	contentType string,
	metadata map[string]string,
	reader io.Reader) (*jetstream.ObjectInfo, error)

PutObjectStream writes an object using a streaming reader.

func (*NatsObjectClient) PutObjectTags added in v0.4.0

func (c *NatsObjectClient) PutObjectTags(ctx context.Context, bucket string, key string, tagMetadata map[string]string) error

PutObjectTags sets or replaces tags on an existing object. Tags are stored in metadata with "x-amz-tag-" prefix.

func (*NatsObjectClient) Stats added in v0.3.1

func (c *NatsObjectClient) Stats() nats.Statistics

Stats returns NATS statistics

type NatsObjectClientOptions added in v0.3.9

type NatsObjectClientOptions struct {
	Replicas int
}

type PartMeta added in v0.3.1

type PartMeta struct {
	Number   int    `json:"number"`
	ETag     string `json:"etag"`
	Size     uint64 `json:"size"`
	StoredAt int64  `json:"stored_at_unix"`
}

PartMeta describes a single part in a multipart upload. It records the part number, ETag (checksum), size in bytes, and the time the part was stored (Unix seconds).

type UploadMeta added in v0.3.1

type UploadMeta struct {
	UploadID  string           `json:"upload_id"`
	Bucket    string           `json:"bucket"`
	Key       string           `json:"key"`
	Initiated time.Time        `json:"initiated"`
	Owner     string           `json:"owner,omitempty"` // optional, auth principal
	MinPartSz int64            `json:"min_part_size"`   // default 5MiB
	MaxParts  int              `json:"max_parts"`       // default 10000
	Parts     map[int]PartMeta `json:"-"`               // Not persisted, populated on-demand
}

UploadMeta captures the server-side state of a multipart upload. It includes identifiers (UploadID, Bucket, Key), initiation time (UTC), optional owner, and constraints (minimum part size and max parts). The JSON value is persisted in a Key-Value store under a session-specific key. Individual part metadata is stored in separate KV entries to avoid write conflicts. The Parts field is populated on-demand when calling ListParts or CompleteMultipartUpload.

Jump to

Keyboard shortcuts

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