-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
189 lines (159 loc) · 4.08 KB
/
example_test.go
File metadata and controls
189 lines (159 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package storage_test
import (
"archive/tar"
"context"
"io"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
_ "github.com/joho/godotenv/autoload"
storage "github.com/tigrisdata/storage-go"
)
func ExampleNew() {
ctx := context.Background()
// Create a new Tigris client with default options
client, err := storage.New(ctx)
if err != nil {
log.Fatal(err)
}
_ = client
// Create a client with custom options
client, err = storage.New(ctx,
storage.WithFlyEndpoint(), // Use fly.io optimized endpoint
storage.WithGlobalEndpoint(), // Use globally available endpoint (default)
storage.WithRegion("auto"), // Specify a region
// storage.WithAccessKeypair(key, secret), // Set access credentials
)
if err != nil {
log.Fatal(err)
}
_ = client
}
func ExampleClient_CreateSnapshotEnabledBucket() {
ctx := context.Background()
client, err := storage.New(ctx)
if err != nil {
log.Fatal(err)
}
// Create a bucket with snapshot support enabled
output, err := client.CreateSnapshotEnabledBucket(ctx, &s3.CreateBucketInput{
Bucket: aws.String("my-bucket"),
})
if err != nil {
log.Fatal(err)
}
_ = output
}
func ExampleClient_CreateBucketSnapshot() {
ctx := context.Background()
client, err := storage.New(ctx)
if err != nil {
log.Fatal(err)
}
// Create a snapshot with a description
output, err := client.CreateBucketSnapshot(ctx, "Initial backup", &s3.CreateBucketInput{
Bucket: aws.String("my-bucket"),
})
if err != nil {
log.Fatal(err)
}
_ = output
}
func ExampleClient_CreateBucketFork() {
ctx := context.Background()
client, err := storage.New(ctx)
if err != nil {
log.Fatal(err)
}
// Creates a new bucket "my-bucket-fork" as a fork of "my-bucket"
output, err := client.CreateBucketFork(ctx, "my-bucket", "my-bucket-fork")
if err != nil {
log.Fatal(err)
}
_ = output
}
func ExampleClient_ListBucketSnapshots() {
ctx := context.Background()
client, err := storage.New(ctx)
if err != nil {
log.Fatal(err)
}
// List all snapshots for a bucket
snapshots, err := client.ListBucketSnapshots(ctx, "my-bucket")
if err != nil {
log.Fatal(err)
}
_ = snapshots
}
func ExampleClient_HeadBucketForkOrSnapshot() {
ctx := context.Background()
client, err := storage.New(ctx)
if err != nil {
log.Fatal(err)
}
// Get fork/snapshot metadata for a bucket
info, err := client.HeadBucketForkOrSnapshot(ctx, &s3.HeadBucketInput{
Bucket: aws.String("my-bucket"),
})
if err != nil {
log.Fatal(err)
}
_ = info.SnapshotsEnabled // true if snapshots are enabled
_ = info.SourceBucket // The bucket this was forked from
_ = info.SourceBucketSnapshot // The snapshot this was forked from
_ = info.IsForkParent // true if there are forks of this bucket
}
func ExampleClient_RenameObject() {
ctx := context.Background()
client, err := storage.New(ctx)
if err != nil {
log.Fatal(err)
}
// Rename an object in-place without copying data
_, err = client.RenameObject(ctx, &s3.CopyObjectInput{
Bucket: aws.String("my-bucket"),
CopySource: aws.String("my-bucket/old-name.txt"),
Key: aws.String("new-name.txt"),
})
if err != nil {
log.Fatal(err)
}
}
func ExampleClient_BundleObjects() {
ctx := context.Background()
client, err := storage.New(ctx)
if err != nil {
log.Fatal(err) // handle the error here
}
// Fetch multiple objects as a streaming tar archive in a single request.
output, err := client.BundleObjects(ctx, &storage.BundleObjectsInput{
Bucket: "my-dataset-bucket",
Keys: []string{
"train/img_001.jpg",
"train/img_002.jpg",
"train/img_003.jpg",
},
})
if err != nil {
log.Fatal(err) // handle the error here
}
defer output.Body.Close()
// Iterate tar entries as they arrive.
tr := tar.NewReader(output.Body)
for {
hdr, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err) // handle the error here
}
// Read the object content.
data, err := io.ReadAll(tr)
if err != nil {
log.Fatal(err) // handle the error here
}
_ = hdr.Name // object key, e.g. "train/img_001.jpg"
_ = data // object content
}
}