gpt4 book ai didi

go - minio客户端(GO SDK)API调用不起作用

转载 作者:行者123 更新时间:2023-12-01 22:24:58 25 4
gpt4 key购买 nike

没有API调用可在本地运行的minio服务器上执行功能

这是我连接到服务器并列出存储桶的方式

// Use a secure connection.
ssl := false

// Initialize minio client object.
minioClient, err := minio.New("localhost:9000", "minioadmin", "minioadmin", ssl)
if err != nil {
fmt.Println(err)
return
}

err = minioClient.MakeBucket("testlalabucket", "")
fmt.Println(err)

抛出错误
[] XML syntax error on line 10: element <link> closed by </head>

使用CLI与minio服务器通信:
➜  ~ mc ls localminio
mc: <ERROR> Unable to list folder. XML syntax error on line 10: element <link> closed by </head>

进行其他操作(制造水桶)
mc: <ERROR> Unable to make bucket `localminio/mylalabucket`. The specified bucket does not exist.
(1) mb-main.go:145 cmd.mainMakeBucket(..) Tags: [localminio/mylalabucket]
(0) client-s3.go:1120 cmd.(*s3Client).MakeBucket(..)

我可以访问minio服务器的UI来执行所有这些操作,但无法通过API来执行。

最佳答案

SDK版本可能与服务器版本不匹配。这是一个有效的完整示例:

  • 在docker中启动服务器
    docker run -p 9000:9000 minio/minio:RELEASE.2020-02-27T00-23-05Z server /data  
  • 如下创建test.go文件
    package main

    import (
    "log"

    "github.com/minio/minio-go/v6"
    )

    func main() {
    endpoint := "localhost:9000"
    accessKeyID := "minioadmin"
    secretAccessKey := "minioadmin"
    useSSL := false

    // Initialize minio client object.
    minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
    if err != nil {
    log.Fatalln(err)
    }

    bucketName := "testlalabucket"
    err = minioClient.MakeBucket(bucketName, "")

    if err != nil {
    // Check to see if we already own this bucket (which happens if you run this twice)
    exists, errBucketExists := minioClient.BucketExists(bucketName)
    if errBucketExists == nil && exists {
    log.Printf("We already own %s\n", bucketName)
    } else {
    log.Fatalln(err)
    }
    }

    buckets, err := minioClient.ListBuckets()
    if err != nil {
    log.Fatalln(err)
    }

    for _, bucket := range buckets {
    log.Println(bucket)
    }
    }
  • 运行GO111MODULE=on go run test.go
  • 关于go - minio客户端(GO SDK)API调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60524700/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com