Skip to content

Instantly share code, notes, and snippets.

@krisis
Created January 4, 2017 05:14
Show Gist options
  • Save krisis/46fabb7c7fb178f9712cc1890938b17f to your computer and use it in GitHub Desktop.
Save krisis/46fabb7c7fb178f9712cc1890938b17f to your computer and use it in GitHub Desktop.
Go program using minio-go to upload objects in parallel
package main
import (
"fmt"
"sync"
"os"
"github.com/minio/minio-go"
)
func main() {
mc1, err := minio.New("localhost:9001", "minio", "minio123", false)
if err != nil {
fmt.Println(err)
return
}
mc2, err := minio.New("localhost:9002", "minio", "minio123", false)
if err != nil {
fmt.Println(err)
return
}
wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
go func(gid int) {
defer wg.Done()
file, err := os.Open(`c:\Users\Atul\Downloads\go1.7.4.windows-amd64.msi`)
if err != nil {
fmt.Println(gid+1, err)
return
}
defer file.Close()
var mc *minio.Client
if gid % 2 == 0 {
mc = mc1
} else {
mc = mc2
}
_, err = mc.PutObject("test", "minio.exe", file, "application/octet-stream")
if err != nil {
fmt.Println(gid+1, err)
return
}
fmt.Printf("%d upload was successful\n", gid+1)
}(i)
}
wg.Wait()
fmt.Println("we are done here")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment