go 调用minio sdk

Posted 招财猫2021

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了go 调用minio sdk相关的知识,希望对你有一定的参考价值。

package main

import (
   "context"
   "github.com/minio/minio-go/v7"
   "github.com/minio/minio-go/v7/pkg/credentials"
   "log"
)

func main() {
   ctx := context.Background()
   endpoint := "192.168.1.2:9001"
   accessKeyID := "minioadmin"
   secretAccessKey := "minioadmin"
   useSSL := false

   // Initialize minio client object.
   minioClient, err := minio.New(endpoint, &minio.Options{
      Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
      Secure: useSSL,
   })
   if err != nil {
      log.Fatalln(err)
   }

   log.Printf("%#v\\n", minioClient) // minioClient is now set up

   bucketName := "mymusic"
   location := "us-east-1"

   err = minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{Region: location})
   if err != nil {
      // Check to see if we already own this bucket (which happens if you run this twice)
      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 := "1.text"
   filePath := "D:\\\\test\\\\1.text"
   contentType := "application/text"

   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)
}

以上是关于go 调用minio sdk的主要内容,如果未能解决你的问题,请参考以下文章

docker搭建minio以及java sdk使用

使用 S3 Java SDK 与 S3 兼容存储通信 (minio)

java 使用AWS Java SDK构建本地Minio S3客户端

Java编程系列Minio实现文件上传下载

Java编程系列Minio实现文件上传下载

Java编程系列Minio实现文件上传下载