我已经下载了“go get github.com/Azure/azure-storage-file-go/azfile”这个库。
现在我正在尝试使用 Go SDK 列出共享、文件和目录。
但是我卡住了。如何调用列表共享功能以及如何使用共享 key 对其进行身份验证。
最佳答案
这是我为您提供的示例代码。希望对您有所帮助。
package main
import (
"context"
"fmt"
"log"
"net/url"
"github.com/Azure/azure-storage-file-go/azfile"
)
func main() {
accountName, accountKey := "<your account name>", "<your account key>"
credential, _ := azfile.NewSharedKeyCredential(accountName, accountKey)
serviceURL, _ := url.Parse("https://<your account name>.file.core.windows.net/")
p := azfile.NewPipeline(credential, azfile.PipelineOptions{})
service := azfile.NewServiceURL(*serviceURL, p)
list, _ := service.ListSharesSegment(context.Background(), azfile.Marker{}, azfile.ListSharesOptions{})
for i, item := range list.ShareItems {
fmt.Println(i, item)
}
}
关于azure - 如何使用 Go SDK 列出 Azure 存储中的共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56002146/