azure - 如何使用 Go SDK 列出 Azure 存储中的共享

标签 azure file go storage

我已经下载了“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/

相关文章:

file - 如何在 golang 中创建一个包含 "000000..."数据的 10MB 文件?

types - Go — 如何处理结构类型之间的公共(public)字段

azure - Azure DevOps 管道可以按特定顺序运行吗?

asp.net - 将 ASP.NET Core Razor 页面部署到 Azure 应用服务

c++ - 将文本文件读入二维数组 C++

Java - 将 JSON 字符串数组解析为字符串数组

go - 如何使用Ancestor查询和最新的golang库从数据存储中读取

azure - 运行命令脚本无法识别术语 'az'

c# - HttpClient Gzip 压缩

file - 如何在emacs中写入文件