MCPcopy
hub / github.com/minio/minio-go / main

Function main

examples/s3/getbucketpolicy.go:34–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32)
33
34func main() {
35 // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
36 // dummy values, please replace them with original values.
37
38 // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
39 // This boolean value is the last argument for New().
40
41 // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
42 // determined based on the Endpoint value.
43 s3Client, err := minio.New("s3.amazonaws.com", &minio.Options{
44 Creds: credentials.NewStaticV4("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", ""),
45 Secure: true,
46 })
47 if err != nil {
48 log.Fatalln(err)
49 }
50
51 // s3Client.TraceOn(os.Stderr)
52
53 policy, err := s3Client.GetBucketPolicy(context.Background(), "my-bucketname")
54 if err != nil {
55 log.Fatalln(err)
56 }
57
58 // Create policy file
59 localFile, err := os.Create("policy.json")
60 if err != nil {
61 log.Fatalln(err)
62 }
63 defer localFile.Close()
64
65 policyReader := strings.NewReader(policy)
66
67 if _, err := io.Copy(localFile, policyReader); err != nil {
68 log.Fatalln(err)
69 }
70}

Callers

nothing calls this directly

Calls 3

NewStaticV4Function · 0.92
GetBucketPolicyMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected