1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| package main
import ( "context" "log"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" )
func main() { ctx := context.Background() endpoint := "192.168.239.161:80" accessKeyID := "NVOIWRENPG178" secretAccessKey := "ONPOWRGW1981918" useSSL := false
minioClient, err := minio.New(endpoint, &minio.Options{ Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""), Secure: useSSL, }) if err != nil { log.Fatalln(err) }
bucketName := "mybucket"
err = minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{}) if err != nil { exists, errBucketExists := minioClient.BucketExists(ctx, bucketName) if errBucketExists == nil && exists { log.Printf("We already own %s\n", bucketName) } else { log.Fatalln(err) } } else { log.Printf("Successfully created %s\n", bucketName) }
objectName := "gomod" filePath := "go.mod" contentType := "application/octet-stream"
info, err := minioClient.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType}) if err != nil { log.Fatalln(err) }
log.Printf("Successfully uploaded %s of size %d\n", objectName, info.Size) }
|