tigrisheaders

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package tigrisheaders contains Tigris-specific header helpers for the AWS S3 SDK and helpers for interacting with Tigris.

Tigris is a cloud storage service that provides a simple, scalable, and secure object storage solution. It is based on the S3 API, but has additional features that need these helpers.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCompareAndSwap

func WithCompareAndSwap() func(*s3.Options)

WithCompareAndSwap tells Tigris to skip the cache and read the object from its designated region.

This is only used on GET requests.

See the Tigris documentation1 for more information.

Example
package main

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context

func main() {
	// Compare-and-swap (skip cache, read from designated region)
	_, err := client.GetObject(ctx, &s3.GetObjectInput{},
		tigrisheaders.WithCompareAndSwap())
	if err != nil {
		log.Fatal(err)
	}
}

func WithConsistentRead added in v0.7.0

func WithConsistentRead() func(*s3.Options)

WithConsistentRead enables consistent read mode.

func WithCreateObjectIfNotExists

func WithCreateObjectIfNotExists() func(*s3.Options)

WithCreateObjectIfNotExists will create the object if it doesn't exist.

See the Tigris documentation1 for more information.

Example
package main

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context

func main() {
	// Create object only if it doesn't exist
	_, err := client.PutObject(ctx, &s3.PutObjectInput{},
		tigrisheaders.WithCreateObjectIfNotExists())
	if err != nil {
		log.Fatal(err)
	}
}

func WithEnableSnapshot

func WithEnableSnapshot() func(*s3.Options)

WithEnableSnapshot tells Tigris to enable bucket snapshotting when creating buckets.

See the Tigris documentation1 for more information.

func WithForceDelete added in v0.8.0

func WithForceDelete() func(*s3.Options)

WithForceDelete forces deletion of a bucket even when it is not empty.

If the bucket has soft delete enabled, it is moved to a recoverable soft-deleted state for the retention window instead of being permanently removed. Otherwise the bucket and its contents are permanently deleted.

See Tigris documentation1 for more information.

Example
package main

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context

func main() {
	// Delete a bucket even when it is not empty. If the bucket has soft delete
	// enabled, it is moved to a recoverable soft-deleted state instead.
	_, err := client.DeleteBucket(ctx, &s3.DeleteBucketInput{
		Bucket: aws.String("my-bucket"),
	}, tigrisheaders.WithForceDelete())
	if err != nil {
		log.Fatal(err) // handle the error here
	}
}

func WithForkSourceBucket

func WithForkSourceBucket(sourceBucket string) func(*s3.Options)

WithForkSourceBucket sets the source bucket when creating a bucket fork.

See the Tigris documentation1 for more information.

func WithForkSourceBucketSnapshot added in v0.7.0

func WithForkSourceBucketSnapshot(snapshot string) func(*s3.Options)

WithForkSourceBucketSnapshot specifies the snapshot version when forking from a bucket.

func WithHeader

func WithHeader(key, value string) func(*s3.Options)

WithHeader sets an arbitrary HTTP header on the request.

Example
package main

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context

func main() {
	// Set arbitrary HTTP header on request
	_, err := client.PutObject(ctx, &s3.PutObjectInput{},
		tigrisheaders.WithHeader("X-Custom-Header", "value"))
	if err != nil {
		log.Fatal(err)
	}
}

func WithIfEtagMatches

func WithIfEtagMatches(etag string) func(*s3.Options)

WithIfEtagMatches sets the ETag that the object must match.

See the Tigris documentation1 for more information.

Example
package main

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context

func main() {
	// Only proceed if ETag matches
	_, err := client.PutObject(ctx, &s3.PutObjectInput{},
		tigrisheaders.WithIfEtagMatches(`"abc123"`))
	if err != nil {
		log.Fatal(err)
	}
}

func WithListSnapshots

func WithListSnapshots(bucketName string) func(*s3.Options)

WithListSnapshots lists snapshots for the given bucket.

This is different from WithTakeSnapshot which creates a snapshot.

See the Tigris documentation1 for more information.

func WithModifiedSince

func WithModifiedSince(modifiedSince time.Time) func(*s3.Options)

WithModifiedSince lets you proceed with operation if object was modified after provided date (RFC1123).

See the Tigris documentation1 for more information.

Example
package main

import (
	"context"
	"log"
	"time"

	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context

func main() {
	// Only proceed if modified since date
	_, err := client.GetObject(ctx, &s3.GetObjectInput{},
		tigrisheaders.WithModifiedSince(time.Now().Add(-24*time.Hour)))
	if err != nil {
		log.Fatal(err)
	}
}

func WithQuery

func WithQuery(query string) func(*s3.Options)

WithQuery lets you filter objects in a ListObjectsV2 request.

This functions like the WHERE clause in SQL, but for S3 objects. For more information, see the Tigris documentation1.

Example
package main

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context

func main() {
	// Filter objects with a SQL-like WHERE clause
	_, err := client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{
		Bucket: aws.String("my-bucket"),
	}, tigrisheaders.WithQuery("WHERE `Last-Modified` > \"2023-01-15T08:30:00Z\" AND `Content-Type` = \"text/javascript\""))
	if err != nil {
		log.Fatal(err)
	}
}

func WithRename

func WithRename() func(*s3.Options)

WithRename tells Tigris to do an in-place rename of objects instead of copying them when using a CopyObject call.

See the Tigris documentation1 for more information.

func WithSnapshotVersion

func WithSnapshotVersion(snapshotVersion string) func(*s3.Options)

WithSnapshotVersion tells Tigris to use a given snapshot when doing ListObjectsV2, GetObject, or HeadObject calls.

See the Tigris documentation1 for more information.

Example
package main

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context

func main() {
	// List objects from a specific snapshot
	_, err := client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{
		Bucket: aws.String("my-bucket"),
	}, tigrisheaders.WithSnapshotVersion("snapshot-id"))
	if err != nil {
		log.Fatal(err)
	}

	// Get object from a specific snapshot
	_, err = client.GetObject(ctx, &s3.GetObjectInput{
		Bucket: aws.String("my-bucket"),
		Key:    aws.String("file.txt"),
	}, tigrisheaders.WithSnapshotVersion("snapshot-id"))
	if err != nil {
		log.Fatal(err)
	}
}

func WithSoftDelete added in v0.8.0

func WithSoftDelete(days ...int) func(*s3.Options)

WithSoftDelete enables soft delete when creating a bucket. Once enabled, deleting an object or the bucket moves it into a recoverable soft-deleted state for a retention window instead of removing it immediately.

Call with no arguments for the default 7-day retention window. Pass a single integer between 7 and 90 to set a custom window in days; only the first value is used. Values outside the 7-90 range are rejected by the server.

See Tigris documentation1 for more information.

Example
package main

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context

func main() {
	// Create a bucket with the default 7-day soft delete retention window
	_, err := client.CreateBucket(ctx, &s3.CreateBucketInput{
		Bucket: aws.String("my-bucket"),
	}, tigrisheaders.WithSoftDelete())
	if err != nil {
		log.Fatal(err) // handle the error here
	}

	// Create a bucket with a custom 30-day retention window
	_, err = client.CreateBucket(ctx, &s3.CreateBucketInput{
		Bucket: aws.String("my-other-bucket"),
	}, tigrisheaders.WithSoftDelete(30))
	if err != nil {
		log.Fatal(err) // handle the error here
	}
}

func WithStaticReplicationRegions

func WithStaticReplicationRegions(regions []Region) func(*s3.Options)

WithStaticReplicationRegions sets the regions where the object will be replicated.

Note that this will cause you to be charged multiple times for the same object, once per region.

Example
package main

import (
	"bytes"
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context
var data []byte

func main() {
	// Replicate to specific regions
	_, err := client.PutObject(ctx, &s3.PutObjectInput{
		Bucket: aws.String("my-bucket"),
		Key:    aws.String("file.txt"),
		Body:   bytes.NewReader(data),
	}, tigrisheaders.WithStaticReplicationRegions([]tigrisheaders.Region{
		tigrisheaders.FRA, // Frankfurt
		tigrisheaders.SJC, // San Jose
	}))
	if err != nil {
		log.Fatal(err)
	}
}

func WithStorageClass added in v0.7.0

func WithStorageClass(storageClass string) func(*s3.Options)

WithStorageClass sets the storage class tier for buckets or objects. Valid values: "STANDARD", "STANDARD_IA", "GLACIER", "GLACIER_IR"

func WithTakeSnapshot

func WithTakeSnapshot(desc string) func(*s3.Options)

WithTakeSnapshot tells Tigris to create a snapshot with the given description on a forkable bucket.

See the Tigris documentation1 for more information.

func WithUnmodifiedSince

func WithUnmodifiedSince(unmodifiedSince time.Time) func(*s3.Options)

WithUnmodifiedSince lets you proceed with operation if object was not modified after provided date (RFC1123).

See the Tigris documentation1 for more information.

Example
package main

import (
	"context"
	"log"
	"time"

	"github.com/aws/aws-sdk-go-v2/service/s3"

	storage "github.com/tigrisdata/storage-go"
	"github.com/tigrisdata/storage-go/tigrisheaders"

	_ "github.com/joho/godotenv/autoload"
)

var client *storage.Client
var ctx context.Context

func main() {
	// Only proceed if unmodified since date
	_, err := client.GetObject(ctx, &s3.GetObjectInput{},
		tigrisheaders.WithUnmodifiedSince(time.Now().Add(-24*time.Hour)))
	if err != nil {
		log.Fatal(err)
	}
}

Types

type Region

type Region string

Region is a Tigris region from the documentation.

https://www.tigrisdata.com/docs/concepts/regions/

const (
	FRA Region = "fra" // Frankfurt, Germany
	GRU Region = "gru" // São Paulo, Brazil
	HKG Region = "hkg" // Hong Kong, China
	IAD Region = "iad" // Ashburn, Virginia, USA
	JNB Region = "jnb" // Johannesburg, South Africa
	LHR Region = "lhr" // London, UK
	MAD Region = "mad" // Madrid, Spain
	NRT Region = "nrt" // Tokyo (Narita), Japan
	ORD Region = "ord" // Chicago, Illinois, USA
	SIN Region = "sin" // Singapore
	SJC Region = "sjc" // San Jose, California, USA
	SYD Region = "syd" // Sydney, Australia

	Europe Region = "eur" // European datacenters
	USA    Region = "usa" // American datacenters
)

Possible Tigris regions.

Jump to

Keyboard shortcuts

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