MCPcopy Create free account
hub / github.com/DoNewsCode/core / Example

Function Example

ots3/example_test.go:10–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8)
9
10func Example() {
11 if os.Getenv("S3_ENDPOINT") == "" {
12 fmt.Println("set S3_ENDPOINT to run this exmaple")
13 return
14 }
15 if os.Getenv("S3_ACCESSKEY") == "" {
16 fmt.Println("set S3_ACCESSKEY to run this exmaple")
17 return
18 }
19 if os.Getenv("S3_ACCESSSECRET") == "" {
20 fmt.Println("set S3_ACCESSSECRET to run this exmaple")
21 return
22 }
23 if os.Getenv("S3_BUCKET") == "" {
24 fmt.Println("set S3_BUCKET to run this exmaple")
25 return
26 }
27 if os.Getenv("S3_REGION") == "" {
28 fmt.Println("set S3_REGION to run this exmaple")
29 return
30 }
31 file, err := os.Open("./testdata/basn0g01-30.png")
32 if err != nil {
33 panic(err)
34 }
35 defer file.Close()
36 uploader := NewManager(os.Getenv("S3_ACCESSKEY"), os.Getenv("S3_ACCESSSECRET"), os.Getenv("S3_ENDPOINT"), os.Getenv("S3_REGION"), os.Getenv("S3_BUCKET"))
37 _ = uploader.CreateBucket(context.Background(), os.Getenv("S3_BUCKET"))
38 url, _ := uploader.Upload(context.Background(), "foo", file)
39 url = strings.Replace(url, os.Getenv("S3_ENDPOINT"), "http://example.org", 1)
40 fmt.Println(url)
41
42 // Output:
43 // http://example.org/mybucket/foo.png
44}

Callers

nothing calls this directly

Calls 4

CreateBucketMethod · 0.95
UploadMethod · 0.95
NewManagerFunction · 0.85
CloseMethod · 0.80

Tested by

no test coverage detected