duanbeng1923 2019-05-06 01:15
浏览 74

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

I have download "go get github.com/Azure/azure-storage-file-go/azfile" this library.

Now I am trying to list shares, files and directories using Go SDK.

But I am stuck. How to call listshare function and also how to authenticate it using Shared key.

  • 写回答

1条回答 默认 最新

  • doudou3213 2019-05-06 02:46
    关注

    Here is my sample code for you. Hope it helps.

    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)
        }
    }
    
    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部