go 调用minio sdk【附源码】_招财猫2021

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("%#vn", 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 %sn", bucketName)       } else {          log.Fatalln(err)       }    } else {       log.Printf("Successfully created %sn", 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 %dn", objectName, info.Size) }

本站由小牛团队全力维护,小牛十年了,大家已经步入中年 。本站源码全部经过团队成员测试并调试,价格可能比其它网站略贵几元钱,不解释!
小牛资源 » go 调用minio sdk【附源码】_招财猫2021

发表评论

全站资源亲测可用,价格略高几元,不解释

立即查看 了解详情