doudan5136 2018-10-22 16:35
浏览 128
已采纳

Google Storage:如何检查存储桶是否存在

Using GoLang SDK for google cloud storage.... Cannot find a method to check if a bucket exists.

func (c *Client) Bucket(name string) *BucketHandle

Bucket returns a BucketHandle even if bucket does not exist.

So, how can I check if the bucket exists? I do not want to create the bucket if it does not exist, so cannot take the route of trying to create a bucket and handle errors

  • 写回答

2条回答 默认 最新

  • duanshan1511 2018-10-22 18:42
    关注

    This can be done by using the Attrs function :

    bucket := client.Bucket(bucketName)
    exists,err := bucket.Attrs(ctx)
    if err != nil {
        log.Fatalf("Message: %v",err)
    }
    fmt.Println(exists)
    

    Since err, prints Message: storage: bucket doesn't exist.

    In case you consider that having a function that directly mentions if a bucket exists or not would be useful, I suggest filling a feature request to the Cloud Storage engineering team to consider having it on further releases.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)