]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
examples/golang : Add Golang examples 47091/head
authordux <faithuniterh@tutanota.com>
Fri, 29 Jul 2022 14:24:44 +0000 (14:24 +0000)
committerdux <faithuniterh@tutanota.com>
Fri, 29 Jul 2022 14:24:44 +0000 (14:24 +0000)
Signed-off-by: dux <faithuniterh@tutanota.com>
14 files changed:
examples/golang/README.md [deleted file]
examples/golang/fortuna.txt [deleted file]
examples/golang/go.mod [deleted file]
examples/golang/go.sum [deleted file]
examples/golang/object-upload.go [deleted file]
examples/golang/object-upload/README.md [new file with mode: 0644]
examples/golang/object-upload/fortuna.txt [new file with mode: 0644]
examples/golang/object-upload/go.mod [new file with mode: 0644]
examples/golang/object-upload/go.sum [new file with mode: 0644]
examples/golang/object-upload/object-upload.go [new file with mode: 0644]
examples/golang/topic-creation/README.md [new file with mode: 0644]
examples/golang/topic-creation/go.mod [new file with mode: 0644]
examples/golang/topic-creation/go.sum [new file with mode: 0644]
examples/golang/topic-creation/topic-creation.go [new file with mode: 0644]

diff --git a/examples/golang/README.md b/examples/golang/README.md
deleted file mode 100644 (file)
index 3d8b73d..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-# Introduction
-This directory contains Golang code examples on how to upload an object to an S3 bucket running on a Ceph RGW cluster.
-
-# Prerequisite
-Linux machine running an RGW Ceph cluster. Preferrably started with the ``OSD=1 MON=1 MDS=0 MGR=0 RGW=1 ../src/vstart.sh --debug --new `` command.  
-Go installed on the Linux machine.  
-
-## Workflow Procedure
-1. Install AWS CLI version one on your Linux machine as explained [here](https://docs.aws.amazon.com/cli/v1/userguide/install-linux.html)
-2. Create a bucket on the Ceph cluster with the command 
-```
-aws --endpoint-url http://localhost:8000 s3 mb s3://sample-bucket
-```
-3. Navigate through your file system to where the Go example code is using your terminal.
-4. Run ``` go mod tidy ``` to install the required Go packages on the system.
-5. Run the Go program as ``` go run object-upload.go sample-bucket fortuna.txt ``` on the terminal window to test out object upload to Ceph RGW cluster.
diff --git a/examples/golang/fortuna.txt b/examples/golang/fortuna.txt
deleted file mode 100644 (file)
index 1462405..0000000
+++ /dev/null
@@ -1 +0,0 @@
-This file is being used to test Go upload capabilities to Ceph RGW cluster.
diff --git a/examples/golang/go.mod b/examples/golang/go.mod
deleted file mode 100644 (file)
index 9cb158a..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-module ceph/object-upload
-
-go 1.13
-
-require github.com/aws/aws-sdk-go v1.43.41
diff --git a/examples/golang/go.sum b/examples/golang/go.sum
deleted file mode 100644 (file)
index 8ab2f12..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-github.com/aws/aws-sdk-go v1.43.41 h1:HaazVplP8/t6SOfybQlNUmjAxLWDKdLdX8BSEHFlJdY=
-github.com/aws/aws-sdk-go v1.43.41/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
-github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
-github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
-github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
-github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
-github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
-golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
-golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
-golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
-golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
-golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
-gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/examples/golang/object-upload.go b/examples/golang/object-upload.go
deleted file mode 100644 (file)
index 2d9ca6f..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-package main
-
-import (
-       "fmt"
-       "github.com/aws/aws-sdk-go/aws"
-       "github.com/aws/aws-sdk-go/aws/credentials"
-       "github.com/aws/aws-sdk-go/aws/endpoints"
-       "github.com/aws/aws-sdk-go/aws/session"
-       "github.com/aws/aws-sdk-go/service/s3/s3manager"
-       "os"
-)
-
-func main() {
-
-       if len(os.Args) != 3 {
-               exitErrorf("bucket and file name required\nUsage: %s bucket_name filename",
-                       os.Args[0])
-       }
-
-       bucket := os.Args[1]
-       filename := os.Args[2]
-
-       file, err := os.Open(filename)
-       if err != nil {
-               exitErrorf("Unable to open file %q, %v", filename, err)
-       }
-
-       defer file.Close()
-
-       defaultResolver := endpoints.DefaultResolver()
-       s3CustResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
-               if service == "s3" {
-                       return endpoints.ResolvedEndpoint{
-                               URL: "http://127.0.0.1:8000", //Variable substituing endpoint-url
-                       }, nil
-               }
-
-               return defaultResolver.EndpointFor(service, region, optFns...)
-       }
-
-       sess := session.Must(session.NewSessionWithOptions(session.Options{
-               Config: aws.Config{
-                       Region:           aws.String("default"),
-                       Credentials:      credentials.NewStaticCredentials("0555b35654ad1656d804", "h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q==", ""),
-                       S3ForcePathStyle: aws.Bool(true),
-                       EndpointResolver: endpoints.ResolverFunc(s3CustResolverFn),
-               },
-       }))
-
-       uploader := s3manager.NewUploader(sess)
-
-       // Upload the file's body to S3 bucket as an object with the key being the
-       // same as the filename.
-       _, err = uploader.Upload(&s3manager.UploadInput{
-               Bucket: aws.String(bucket),
-               Key:    aws.String(filename),
-               Body:   file,
-       })
-       if err != nil {
-               exitErrorf("Unable to upload %q to %q, %v", filename, bucket, err)
-       }
-
-       fmt.Printf("Successfully uploaded %q to %q\n", filename, bucket)
-}
-
-func exitErrorf(msg string, args ...interface{}) {
-       fmt.Fprintf(os.Stderr, msg+"\n", args...)
-       os.Exit(1)
-}
diff --git a/examples/golang/object-upload/README.md b/examples/golang/object-upload/README.md
new file mode 100644 (file)
index 0000000..1bf1c24
--- /dev/null
@@ -0,0 +1,16 @@
+# Introduction
+This directory contains Golang code examples on how to upload an object to an S3 bucket running on a Ceph RGW cluster.
+
+# Prerequisite
+Linux machine running an RGW Ceph cluster. Preferrably started with the ``OSD=1 MON=1 MDS=0 MGR=0 RGW=1 ../src/vstart.sh --debug --new `` command.  
+Go installed on the Linux machine.  
+
+## Workflow Procedure
+1. Install AWS CLI version one on your Linux machine as explained [here](https://docs.aws.amazon.com/cli/v1/userguide/install-linux.html)
+2. Create a bucket on the Ceph cluster with the command 
+```
+aws --endpoint-url http://localhost:8000 s3 mb s3://sample-bucket
+```
+3. Navigate through your file system to where the Golang example code exist on your terminal.
+4. Run ``` go mod tidy ``` to install the required Go packages on the system.
+5. Run the Golang program as ``` go run object-upload.go -b sample-bucket -f fortuna.txt ``` on the terminal window to test out object upload to Ceph RGW cluster.
diff --git a/examples/golang/object-upload/fortuna.txt b/examples/golang/object-upload/fortuna.txt
new file mode 100644 (file)
index 0000000..1462405
--- /dev/null
@@ -0,0 +1 @@
+This file is being used to test Go upload capabilities to Ceph RGW cluster.
diff --git a/examples/golang/object-upload/go.mod b/examples/golang/object-upload/go.mod
new file mode 100644 (file)
index 0000000..9cb158a
--- /dev/null
@@ -0,0 +1,5 @@
+module ceph/object-upload
+
+go 1.13
+
+require github.com/aws/aws-sdk-go v1.43.41
diff --git a/examples/golang/object-upload/go.sum b/examples/golang/object-upload/go.sum
new file mode 100644 (file)
index 0000000..8ab2f12
--- /dev/null
@@ -0,0 +1,24 @@
+github.com/aws/aws-sdk-go v1.43.41 h1:HaazVplP8/t6SOfybQlNUmjAxLWDKdLdX8BSEHFlJdY=
+github.com/aws/aws-sdk-go v1.43.41/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
+github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
+github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
+github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
+golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
+golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
+gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/examples/golang/object-upload/object-upload.go b/examples/golang/object-upload/object-upload.go
new file mode 100644 (file)
index 0000000..82f09ca
--- /dev/null
@@ -0,0 +1,84 @@
+package main
+
+import (
+       "flag"
+       "fmt"
+       "os"
+
+       "github.com/aws/aws-sdk-go/aws"
+       "github.com/aws/aws-sdk-go/aws/credentials"
+       "github.com/aws/aws-sdk-go/aws/endpoints"
+       "github.com/aws/aws-sdk-go/aws/session"
+       "github.com/aws/aws-sdk-go/service/s3/s3manager"
+)
+
+func main() {
+       bucket := flag.String("b", "", "The name of the bucket")
+       filename := flag.String("f", "", "Complete file path to object to be uploaded")
+       flag.Parse()
+
+       if *bucket == "" {
+               fmt.Println("You must supply the name of the bucket")
+               fmt.Println("-b BUCKET")
+               return
+       }
+
+       if *filename == "" {
+               fmt.Println("You must supply the object to be uploaded")
+               fmt.Println("-f FILE/FILEPATH")
+               return
+       }
+
+       file, err := os.Open(*filename)
+       if err != nil {
+               exitErrorf("Unable to open file %q, %v", filename, err)
+       }
+
+       defer file.Close()
+
+       //Ceph RGW Cluster credentials
+       access_key := "0555b35654ad1656d804"
+       secret_key := "h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=="
+       token_id := ""
+       url := "http://127.0.0.1:8000"
+
+       defaultResolver := endpoints.DefaultResolver()
+       s3CustResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
+               if service == "s3" {
+                       return endpoints.ResolvedEndpoint{
+                               URL: url,
+                       }, nil
+               }
+
+               return defaultResolver.EndpointFor(service, region, optFns...)
+       }
+
+       sess := session.Must(session.NewSessionWithOptions(session.Options{
+               Config: aws.Config{
+                       Region:           aws.String("default"),
+                       Credentials:      credentials.NewStaticCredentials(access_key, secret_key, token_id),
+                       S3ForcePathStyle: aws.Bool(true),
+                       EndpointResolver: endpoints.ResolverFunc(s3CustResolverFn),
+               },
+       }))
+
+       uploader := s3manager.NewUploader(sess)
+
+       // Upload the file's body to S3 bucket as an object with the key being the
+       // same as the filename.
+       _, err = uploader.Upload(&s3manager.UploadInput{
+               Bucket: bucket,
+               Key:    filename,
+               Body:   file,
+       })
+       if err != nil {
+               exitErrorf("Unable to upload %q to %q, %v", *filename, *bucket, err)
+       }
+
+       fmt.Printf("Successfully uploaded %q to %q\n", *filename, *bucket)
+}
+
+func exitErrorf(msg string, args ...interface{}) {
+       fmt.Fprintf(os.Stderr, msg+"\n", args...)
+       os.Exit(1)
+}
diff --git a/examples/golang/topic-creation/README.md b/examples/golang/topic-creation/README.md
new file mode 100644 (file)
index 0000000..3033a86
--- /dev/null
@@ -0,0 +1,11 @@
+# Introduction
+This directory contains Golang code example on how to create an SNS Topic on a Ceph RGW cluster.
+
+# Prerequisite
+Linux machine running an RGW Ceph cluster. Preferrably started with the ``OSD=1 MON=1 MDS=0 MGR=0 RGW=1 ../src/vstart.sh --debug --new `` command.  
+Go installed on the Linux machine.  
+
+## Workflow Procedure
+1. Navigate through your file system to where the Golang example code exists on your terminal.
+2. Run ``` go mod tidy ``` to install the required Golang packages on the system.
+3. Run the Golang program as ``` go run topic-creation.go -t sample-topic-1 -a '{"push-endpoint": "http://127.0.0.1:10900"}' ``` on the terminal window to create SNS topic with custom attributes.   
diff --git a/examples/golang/topic-creation/go.mod b/examples/golang/topic-creation/go.mod
new file mode 100644 (file)
index 0000000..4b4f7fa
--- /dev/null
@@ -0,0 +1,5 @@
+module examples/topic-creation
+
+go 1.13
+
+require github.com/aws/aws-sdk-go v1.44.61
diff --git a/examples/golang/topic-creation/go.sum b/examples/golang/topic-creation/go.sum
new file mode 100644 (file)
index 0000000..4c3ec38
--- /dev/null
@@ -0,0 +1,24 @@
+github.com/aws/aws-sdk-go v1.44.61 h1:NcpLSS3Z0MiVQIYugx4I40vSIEEAXT0baO684ExNRco=
+github.com/aws/aws-sdk-go v1.44.61/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
+github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
+github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
+github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
+golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
+golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
+gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/examples/golang/topic-creation/topic-creation.go b/examples/golang/topic-creation/topic-creation.go
new file mode 100644 (file)
index 0000000..128358f
--- /dev/null
@@ -0,0 +1,81 @@
+package main
+
+import (
+       "encoding/json"
+       "flag"
+       "fmt"
+       "os"
+
+       "github.com/aws/aws-sdk-go/aws"
+       "github.com/aws/aws-sdk-go/aws/credentials"
+       "github.com/aws/aws-sdk-go/aws/endpoints"
+       "github.com/aws/aws-sdk-go/aws/session"
+       "github.com/aws/aws-sdk-go/service/sns"
+)
+
+func main() {
+       topic := flag.String("t", "", "The name of the topic")
+       attributes := flag.String("a", "", "Topic attributes needed")
+       flag.Parse()
+
+       attributesmap := map[string]*string{}
+       err := json.Unmarshal([]byte(*attributes), &attributesmap) // convert JSON string to Go map
+       if err != nil {
+               exitErrorf("Check your JSON String for any errors: %s : %s", err, *attributes)
+       }
+
+       if *topic == "" {
+               fmt.Println("You must supply the name of the topic")
+               fmt.Println("-t TOPIC")
+               return
+       }
+
+       if *attributes == "" {
+               fmt.Println("You must supply topic attributes")
+               fmt.Println("-a ATTRIBUTES")
+               return
+       }
+       //Ceph RGW Cluster credentials
+       access_key := "0555b35654ad1656d804"
+       secret_key := "h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=="
+       token_id := ""
+       url := "http://127.0.0.1:8000"
+
+       defaultResolver := endpoints.DefaultResolver()
+       snsCustResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
+               if service == "sns" {
+                       return endpoints.ResolvedEndpoint{
+                               URL: url,
+                       }, nil
+               }
+
+               return defaultResolver.EndpointFor(service, region, optFns...)
+       }
+
+       sess := session.Must(session.NewSessionWithOptions(session.Options{
+               Config: aws.Config{
+                       Region:           aws.String("default"),
+                       Credentials:      credentials.NewStaticCredentials(access_key, secret_key, token_id),
+                       S3ForcePathStyle: aws.Bool(true),
+                       EndpointResolver: endpoints.ResolverFunc(snsCustResolverFn),
+               },
+       }))
+
+       client := sns.New(sess)
+
+       results, err := client.CreateTopic(&sns.CreateTopicInput{
+               Attributes: attributesmap,
+               Name:       topic,
+       })
+
+       if err != nil {
+               exitErrorf("Unable to create topic %s, %s", *topic, err)
+       }
+
+       fmt.Printf("Succesfully created %s \n", *results.TopicArn)
+}
+
+func exitErrorf(msg string, args ...interface{}) {
+       fmt.Fprintf(os.Stderr, msg+"\n", args...)
+       os.Exit(1)
+}