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 ¶
- func WithCompareAndSwap() func(*s3.Options)
- func WithCreateObjectIfNotExists() func(*s3.Options)
- func WithEnableSnapshot() func(*s3.Options)
- func WithForkSourceBucket(sourceBucket string) func(*s3.Options)
- func WithHeader(key, value string) func(*s3.Options)
- func WithIfEtagMatches(etag string) func(*s3.Options)
- func WithListSnapshots(bucketName string) func(*s3.Options)
- func WithModifiedSince(modifiedSince time.Time) func(*s3.Options)
- func WithQuery(query string) func(*s3.Options)
- func WithRename() func(*s3.Options)
- func WithSnapshotVersion(snapshotVersion string) func(*s3.Options)
- func WithStaticReplicationRegions(regions []Region) func(*s3.Options)
- func WithTakeSnapshot(desc string) func(*s3.Options)
- func WithUnmodifiedSince(unmodifiedSince time.Time) func(*s3.Options)
- type Region
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithCompareAndSwap ¶
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)
}
}
Output:
func WithCreateObjectIfNotExists ¶
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)
}
}
Output:
func WithEnableSnapshot ¶
WithEnableSnapshot tells Tigris to enable bucket snapshotting when creating buckets.
See the Tigris documentation1 for more information.
func WithForkSourceBucket ¶
WithForkSourceBucket sets the source bucket when creating a bucket fork.
See the Tigris documentation1 for more information.
func WithHeader ¶
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)
}
}
Output:
func WithIfEtagMatches ¶
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)
}
}
Output:
func WithListSnapshots ¶
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 ¶
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)
}
}
Output:
func WithQuery ¶
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)
}
}
Output:
func WithRename ¶
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 ¶
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)
}
}
Output:
func WithStaticReplicationRegions ¶
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)
}
}
Output:
func WithTakeSnapshot ¶
WithTakeSnapshot tells Tigris to create a snapshot with the given description on a forkable bucket.
See the Tigris documentation1 for more information.
func WithUnmodifiedSince ¶
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)
}
}
Output:
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.