英文:
Replace variable with a blank identifier in Go package
问题
当我在第25行替换变量resp
时,我得到了错误:=左侧没有新变量
,代码无法编译。我该如何用空标识符替换变量以丢弃响应?
谢谢您的提前帮助!
package main
import (
"context"
"fmt"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("Authentication failure: %+v", err)
}
ctx := context.Background()
//data := "Hello world!"
blobURL := "https://STORGEACCOUNT.blob.core.windows.net/CONTAINER/BLOB.txt"
blockBlob, err := azblob.NewBlockBlobClient(blobURL, cred, nil)
_, err = blockBlob.Delete(ctx, nil)
if err != nil {
log.Fatalf("Failure: %+v", err)
}
fmt.Println("删除成功")
}
英文:
When I replace the variable resp
on line 25 I get the error no new variables on left side of :=
and the code won't compile. How can I replace the variable with a blank identifer to throw away the response?
Thank you in advance!
package main
import (
"context"
"fmt"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("Authentication failure: %+v", err)
}
ctx := context.Background()
//data := "Hello world!"
blobURL := "https://STORGEACCOUNT.blob.core.windows.net/CONTAINER/BLOB.txt"
blockBlob, err := azblob.NewBlockBlobClient(blobURL, cred, nil)
resp, err := blockBlob.Delete(ctx, nil)
if err != nil {
log.Fatalf("Failure: %+v", err)
}
fmt.Println(resp)
}
答案1
得分: 1
短形式声明要求你至少声明一个新变量。当你用_
替换resp
时,这个要求就不再满足,因为err
已经被定义了。所以:
_, err = blockBlob.Delete(ctx, nil)
英文:
Short-form declarations require you to declare at least one new variable. When you replace resp
with _
, this is no longer satisfied because err
is already defined. So:
_, err = blockBlob.Delete(ctx, nil)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论