Skip to content

Commit

Permalink
Makefile: Fix examples target (minio#1395)
Browse files Browse the repository at this point in the history
`examples` was not working properly, make it work and fix minio-go API
examples.
  • Loading branch information
vadmeste authored Oct 14, 2020
1 parent 14baba9 commit 85e5bbf
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 66 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
GOPATH := $(shell go env GOPATH)
TMPDIR := $(shell mktemp -d)

all: checks

Expand All @@ -20,7 +21,7 @@ test:
@GO111MODULE=on SERVER_ENDPOINT=localhost:9000 ACCESS_KEY=minio SECRET_KEY=minio123 ENABLE_HTTPS=1 MINT_MODE=full go test -race -v ./...

examples:
@mkdir -p /tmp/examples && for i in $(echo examples/s3/*); do go build -o /tmp/examples/$(basename ${i:0:-3}) ${i}; done
@$(foreach v,$(wildcard examples/s3/*), go build -o ${TMPDIR}/$(basename $(v)) $(v) || exit 1;)

functional-test:
@GO111MODULE=on SERVER_ENDPOINT=localhost:9000 ACCESS_KEY=minio SECRET_KEY=minio123 ENABLE_HTTPS=1 MINT_MODE=full go run functional_tests.go
Expand Down
2 changes: 1 addition & 1 deletion examples/s3/composeobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func main() {
}

// Create slice of sources.
srcs := []minio.SourceInfo{src1, src2, src3}
srcs := []minio.CopySrcOptions{src1, src2, src3}

// Prepare destination encryption key
encKey, _ := encrypt.NewSSEC([]byte{8, 9, 0})
Expand Down
2 changes: 1 addition & 1 deletion examples/s3/copyobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
}

// Initiate copy object.
ui, err = s3Client.CopyObject(context.Background(), dst, src)
ui, err := s3Client.CopyObject(context.Background(), dst, src)
if err != nil {
log.Fatalln(err)
}
Expand Down
13 changes: 6 additions & 7 deletions examples/s3/getbucketlifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2015-2017 MinIO, Inc.
* Copyright 2015-2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,10 +21,9 @@ package main

import (
"context"
"io"
"encoding/xml"
"log"
"os"
"strings"

"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
Expand Down Expand Up @@ -55,16 +54,16 @@ func main() {
log.Fatalln(err)
}

// Create lifecycle file
// Save the lifecycle document to a 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 {
enc := xml.NewEncoder(localLifecycleFile)
enc.Indent(" ", " ")
if err := enc.Encode(lifecycle); err != nil {
log.Fatalln(err)
}
}
2 changes: 1 addition & 1 deletion examples/s3/getobjecttagging.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func main() {
log.Fatalln(err)
}

tags, err := s3Client.GetObjectTagging(context.Background(), "my-bucketname", "my-objectname")
tags, err := s3Client.GetObjectTagging(context.Background(), "my-bucketname", "my-objectname", minio.GetObjectTaggingOptions{})
if err != nil {
log.Fatalln(err)
}
Expand Down
20 changes: 10 additions & 10 deletions examples/s3/listobjects-N.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ func main() {

// List 'N' number of objects from a bucket-name with a matching prefix.
listObjectsN := func(bucket, prefix string, recursive bool, N int) (objsInfo []minio.ObjectInfo, err error) {
// Create a done channel to control 'ListObjects' go routine.
doneCh := make(chan struct{}, 1)

// Free the channel upon return.
defer close(doneCh)

ctx, cancel := context.WithCancel(context.Background())
// Indicate ListObjects go-routine to exit and stop feeding the objectInfo channel.
defer cancel()
i := 1
for object := range s3Client.ListObjects(context.Background(), bucket, prefix, recursive, doneCh) {
opts := minio.ListObjectsOptions{
UseV1: true,
Prefix: prefix,
Recursive: recursive,
}
for object := range s3Client.ListObjects(ctx, bucket, opts) {
if object.Err != nil {
return nil, object.Err
}
i++
// Verify if we have printed N objects.
if i == N {
// Indicate ListObjects go-routine to exit and stop
// feeding the objectInfo channel.
doneCh <- struct{}{}
break
}
objsInfo = append(objsInfo, object)
}
Expand Down
12 changes: 6 additions & 6 deletions examples/s3/listobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func main() {
return
}

// Create a done channel to control 'ListObjects' go routine.
doneCh := make(chan struct{})

// Indicate to our routine to exit cleanly upon return.
defer close(doneCh)
opts := minio.ListObjectsOptions{
UseV1: true,
Prefix: "my-prefixname",
Recursive: true,
}

// List all objects from a bucket-name with a matching prefix.
for object := range s3Client.ListObjects(context.Background(), "my-bucketname", "my-prefixname", true, doneCh) {
for object := range s3Client.ListObjects(context.Background(), "my-bucketname", opts) {
if object.Err != nil {
fmt.Println(object.Err)
return
Expand Down
11 changes: 5 additions & 6 deletions examples/s3/listobjectsV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ func main() {
return
}

// Create a done channel to control 'ListObjects' go routine.
doneCh := make(chan struct{})

// Indicate to our routine to exit cleanly upon return.
defer close(doneCh)
opts := minio.ListObjectsOptions{
Recursive: true,
Prefix: "my-prefixname",
}

// List all objects from a bucket-name with a matching prefix.
for object := range s3Client.ListObjectsV2(context.Background(), "my-bucketname", "my-prefixname", true, doneCh) {
for object := range s3Client.ListObjects(context.Background(), "my-bucketname", opts) {
if object.Err != nil {
fmt.Println(object.Err)
return
Expand Down
12 changes: 6 additions & 6 deletions examples/s3/listobjectsV2WithMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func main() {
return
}

// Create a done channel to control 'ListObjects' go routine.
doneCh := make(chan struct{})

// Indicate to our routine to exit cleanly upon return.
defer close(doneCh)
opts := minio.ListObjectsOptions{
WithMetadata: true,
Prefix: "my-prefixname",
Recursive: true,
}

// List all objects from a bucket-name with a matching prefix.
for object := range s3Client.ListObjectsV2WithMetadata(context.Background(), "my-bucketname", "my-prefixname", true, doneCh) {
for object := range s3Client.ListObjects(context.Background(), "my-bucketname", opts) {
if object.Err != nil {
fmt.Println(object.Err)
return
Expand Down
6 changes: 5 additions & 1 deletion examples/s3/makebucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func main() {
log.Fatalln(err)
}

err = s3Client.MakeBucket(context.Background(), "my-bucketname", "us-east-1")
opts := minio.MakeBucketOptions{
Region: "us-east-1",
}

err = s3Client.MakeBucket(context.Background(), "my-bucketname", opts)
if err != nil {
log.Fatalln(err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/s3/putobjecttagging.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
if err != nil {
log.Fatalln(err)
}
err = s3Client.PutObjectTagging(context.Background(), "my-bucketname", "my-objectname", t)
err = s3Client.PutObjectTagging(context.Background(), "my-bucketname", "my-objectname", t, minio.PutObjectTaggingOptions{})
if err != nil {
log.Fatalln(err)
}
Expand Down
15 changes: 5 additions & 10 deletions examples/s3/removeobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,23 @@ func main() {
log.Fatalln(err)
}

objectsCh := make(chan string)
objectsCh := make(chan minio.ObjectInfo)

// Send object names that are needed to be removed to objectsCh
go func() {
defer close(objectsCh)

doneCh := make(chan struct{})

// Indicate to our routine to exit cleanly upon return.
defer close(doneCh)

// List all objects from a bucket-name with a matching prefix.
for object := range s3Client.ListObjects(context.Background(), "my-bucketname", "my-prefixname", true, doneCh) {
opts := minio.ListObjectsOptions{Prefix: "my-prefixname", Recursive: true}
for object := range s3Client.ListObjects(context.Background(), "my-bucketname", opts) {
if object.Err != nil {
log.Fatalln(object.Err)
}
objectsCh <- object.Key
objectsCh <- object
}
}()

// Call RemoveObjects API
errorCh := s3Client.RemoveObjects(context.Background(), "my-bucketname", objectsCh)
errorCh := s3Client.RemoveObjects(context.Background(), "my-bucketname", objectsCh, minio.RemoveObjectsOptions{})

// Print errors received from RemoveObjects API
for e := range errorCh {
Expand Down
2 changes: 1 addition & 1 deletion examples/s3/removeobjecttagging.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
if err != nil {
log.Fatalln(err)
}
err = s3Client.RemoveObjectTagging(context.Background(), "my-bucketname", "my-objectname")
err = s3Client.RemoveObjectTagging(context.Background(), "my-bucketname", "my-objectname", minio.RemoveObjectTaggingOptions{})
if err != nil {
log.Fatalln(err)
}
Expand Down
8 changes: 4 additions & 4 deletions examples/s3/setbucketnotification.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ func main() {
// Here you create a new Topic notification
topicArn := notification.NewArn("YOUR-PROVIDER", "YOUR-SERVICE", "YOUR-REGION", "YOUR-ACCOUNT-ID", "YOUR-RESOURCE")
topicConfig := notification.NewConfig(topicArn)
topicConfig.AddEvents(minio.ObjectCreatedAll, minio.ObjectRemovedAll)
topicConfig.AddEvents(notification.ObjectCreatedAll, notification.ObjectRemovedAll)
topicConfig.AddFilterPrefix("photos/")
topicConfig.AddFilterSuffix(".jpg")

// Create a new Queue notification
queueArn := notification.NewArn("YOUR-PROVIDER", "YOUR-SERVICE", "YOUR-REGION", "YOUR-ACCOUNT-ID", "YOUR-RESOURCE")
queueConfig := notification.NewConfig(queueArn)
queueConfig.AddEvents(minio.ObjectRemovedAll)
queueConfig.AddEvents(notification.ObjectRemovedAll)

// Create a new Lambda (CloudFunction)
lambdaArn := notification.NewArn("YOUR-PROVIDER", "YOUR-SERVICE", "YOUR-REGION", "YOUR-ACCOUNT-ID", "YOUR-RESOURCE")
lambdaConfig := notification.NewConfig(lambdaArn)
lambdaConfig.AddEvents(minio.ObjectRemovedAll)
lambdaConfig.AddEvents(notification.ObjectRemovedAll)
lambdaConfig.AddFilterSuffix(".swp")

// Now, set all previously created notification configs
config := &notification.Configuration{}
config := notification.Configuration{}
config.AddTopic(topicConfig)
config.AddQueue(queueConfig)
config.AddLambda(lambdaConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
log.Fatalln(err)
}

err = s3Client.DisableVersioning(context.Background(), "my-bucketname")
err = s3Client.SuspendVersioning(context.Background(), "my-bucketname")
if err != nil {
log.Fatalln(err)
}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/minio/minio-go/v7
go 1.12

require (
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/cheggaaa/pb v1.0.29 // indirect
github.com/google/uuid v1.1.1
github.com/json-iterator/go v1.1.10
github.com/klauspost/cpuid v1.3.1 // indirect
Expand All @@ -14,7 +14,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/rs/xid v1.2.1
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
Expand Down
20 changes: 13 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
github.com/cheggaaa/pb v1.0.29 h1:FckUN5ngEk2LpvuG0fw1GEFx6LtyY2pWI/Z2QgCnEYo=
github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuPxX30=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand All @@ -16,12 +18,18 @@ github.com/klauspost/cpuid v1.2.3 h1:CCtW0xUnWGVINKvE/WWOYKdsPV6mawAtvQuSl8guwQs
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4=
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
Expand All @@ -40,14 +48,11 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
Expand All @@ -61,9 +66,10 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down

0 comments on commit 85e5bbf

Please sign in to comment.