summaryrefslogtreecommitdiff
path: root/examples/s3
diff options
context:
space:
mode:
authorFélix Sipma <felix+debian@gueux.org>2018-12-08 10:31:19 +0100
committerFélix Sipma <felix+debian@gueux.org>2018-12-08 10:31:19 +0100
commit70b5c53e64dae38106cf7e218cc99e6f493f12b9 (patch)
tree188d40029a4de9dcd6340222977941842d1be427 /examples/s3
parentb95d64585c6015489ca8435e4dc422e111f25c67 (diff)
New upstream version 6.0.11
Diffstat (limited to 'examples/s3')
-rw-r--r--examples/s3/getbucketlifecycle.go65
-rw-r--r--examples/s3/getobjectacl.go53
-rw-r--r--examples/s3/selectobject.go73
-rw-r--r--examples/s3/setbucketlifecycle.go50
4 files changed, 241 insertions, 0 deletions
diff --git a/examples/s3/getbucketlifecycle.go b/examples/s3/getbucketlifecycle.go
new file mode 100644
index 0000000..2e3ef41
--- /dev/null
+++ b/examples/s3/getbucketlifecycle.go
@@ -0,0 +1,65 @@
+// +build ignore
+
+/*
+ * Minio Go Library for Amazon S3 Compatible Cloud Storage
+ * Copyright 2015-2017 Minio, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "io"
+ "log"
+ "os"
+ "strings"
+
+ "github.com/minio/minio-go"
+)
+
+func main() {
+ // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
+ // dummy values, please replace them with original values.
+
+ // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
+ // This boolean value is the last argument for New().
+
+ // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
+ // determined based on the Endpoint value.
+ s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ // s3Client.TraceOn(os.Stderr)
+
+ // Get bucket lifecycle from S3
+ lifecycle, err := s3Client.GetBucketLifecycle("my-bucketname")
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ // Create lifecycle file
+ localLifecycleFile, err := os.Create("lifecycle.json")
+ if err != nil {
+ log.Fatalln(err)
+ }
+ defer localLifecycleFile.Close()
+
+ lifecycleReader := strings.NewReader(lifecycle)
+
+ if _, err := io.Copy(localLifecycleFile, lifecycleReader); err != nil {
+ log.Fatalln(err)
+ }
+}
diff --git a/examples/s3/getobjectacl.go b/examples/s3/getobjectacl.go
new file mode 100644
index 0000000..f2bbd95
--- /dev/null
+++ b/examples/s3/getobjectacl.go
@@ -0,0 +1,53 @@
+// +build ignore
+
+/*
+ * Minio Go Library for Amazon S3 Compatible Cloud Storage
+ * Copyright 2018-2019 Minio, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "fmt"
+ "log"
+
+ minio "github.com/minio/minio-go"
+)
+
+func main() {
+ // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname and
+ // my-testfile are dummy values, please replace them with original values.
+
+ // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
+ // This boolean value is the last argument for New().
+
+ // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
+ // determined based on the Endpoint value.
+ s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESS-KEY-HERE", "YOUR-SECRET-KEY-HERE", true)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ objectInfo, err := s3Client.GetObjectACL("my-bucketname", "my-objectname")
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ //print all value header (acl, metadata, standard header value...)
+ for k, v := range objectInfo.Metadata {
+ fmt.Println("key:", k)
+ fmt.Printf(" - value: %v\n", v)
+ }
+}
diff --git a/examples/s3/selectobject.go b/examples/s3/selectobject.go
new file mode 100644
index 0000000..e23ccf8
--- /dev/null
+++ b/examples/s3/selectobject.go
@@ -0,0 +1,73 @@
+// +build ignore
+
+/*
+ * Minio Go Library for Amazon S3 Compatible Cloud Storage
+ * Copyright 2018 Minio, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "context"
+ "io"
+ "log"
+ "os"
+
+ minio "github.com/minio/minio-go"
+)
+
+func main() {
+ // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname and
+ // my-testfile are dummy values, please replace them with original values.
+
+ // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
+ // This boolean value is the last argument for New().
+
+ // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
+ // determined based on the Endpoint value.
+ s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESS-KEY-HERE", "YOUR-SECRET-KEY-HERE", true)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ opts := minio.SelectObjectOptions{
+ Expression: "select count(*) from s3object",
+ ExpressionType: minio.QueryExpressionTypeSQL,
+ InputSerialization: minio.SelectObjectInputSerialization{
+ CompressionType: minio.SelectCompressionNONE,
+ CSV: &minio.CSVInputOptions{
+ FileHeaderInfo: minio.CSVFileHeaderInfoNone,
+ RecordDelimiter: "\n",
+ FieldDelimiter: ",",
+ },
+ },
+ OutputSerialization: minio.SelectObjectOutputSerialization{
+ CSV: &minio.CSVOutputOptions{
+ RecordDelimiter: "\n",
+ FieldDelimiter: ",",
+ },
+ },
+ }
+
+ reader, err := s3Client.SelectObjectContent(context.Background(), "mycsvbucket", "mycsv.csv", opts)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ defer reader.Close()
+
+ if _, err := io.Copy(os.Stdout, reader); err != nil {
+ log.Fatalln(err)
+ }
+}
diff --git a/examples/s3/setbucketlifecycle.go b/examples/s3/setbucketlifecycle.go
new file mode 100644
index 0000000..7eaa946
--- /dev/null
+++ b/examples/s3/setbucketlifecycle.go
@@ -0,0 +1,50 @@
+// +build ignore
+
+/*
+ * Minio Go Library for Amazon S3 Compatible Cloud Storage
+ * Copyright 2015-2017 Minio, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "log"
+
+ "github.com/minio/minio-go"
+)
+
+func main() {
+ // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
+ // dummy values, please replace them with original values.
+
+ // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
+ // This boolean value is the last argument for New().
+
+ // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
+ // determined based on the Endpoint value.
+ s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ // s3Client.TraceOn(os.Stderr)
+
+ // Set lifecycle on a bucket
+ lifecycle := `<LifecycleConfiguration><Rule><ID>expire-bucket</ID><Prefix></Prefix><Status>Enabled</Status><Expiration><Days>365</Days></Expiration></Rule></LifecycleConfiguration>`
+ err = s3Client.SetBucketLifecycle("my-bucketname", lifecycle)
+ if err != nil {
+ log.Fatalln(err)
+ }
+}