英文:
Go + Azure: Calling a method return undefined
问题
我正在尝试使用Go Azure SDK调用通知中心API。
我已经安装了SDK并导入到GO文件中:
package hub
import (
"fmt"
"github.com/Azure/azure-sdk-for-go/arm/notificationhubs"
)
func GetHub() {
if resourceType, err := notificationhubs.Get("sourceGroupName", "NameSpaceValue", "NameOfTheHub"); err != nil {
fmt.Println("Error occurred")
return
}
fmt.Println("Success")
}
然而,当我尝试运行这段代码时,我得到了以下错误:
undefined: notificationhubs.Get
我不确定这是什么意思,因为我的IDE没有关于导入Azure SDK的投诉,所以我认为SDK已经正确导入了。
英文:
Am trying to use Go Azure SDK to call the notification hub api
I have installed the SDK and imported to the GO file :
package hub
import (
"fmt"
"github.com/Azure/azure-sdk-for-go/arm/notificationhubs"
)
func GetHub() {
if resourceType, err := notificationhubs.Get("sourceGroupName", "NameSpaceValue", "NameOfTheHub"); err != nil {
fmt.Println("Error occured")
return
}
fmt.Println("Success")
}
However when am trying to runt he code i got this error
undefined: notificationhubs.Get
And am not sure what it means since my IDE don't complain about importing the Azure SDK so am assuming the SDK is imported correctly.
答案1
得分: 1
你正在尝试使用的函数不存在(https://godoc.org/github.com/Azure/azure-sdk-for-go/arm/notificationhubs)。
你可能正在尝试使用GroupClient.Get
函数;如果是这样的话,你需要获取一个类型为GroupClient
的对象,然后在该对象上调用Get
函数。
英文:
The function you're trying to use doesn't exist (https://godoc.org/github.com/Azure/azure-sdk-for-go/arm/notificationhubs).
You're probably trying to use the function GroupClient.Get
; if that's the case, you need to get an object of type GroupClient
and then call the function Get
on it.
答案2
得分: 0
@cd1是正确的!Get方法不直接属于你导入的命名空间,而是属于该命名空间中存在的一个客户端。为了以这种方式与NotificationsHub进行交互,需要实例化一个GroupClient
,然后运行Get
命令。
import (
hubs "github.com/Azure/azure-sdk-for-go/arm/notificationshub"
)
func main() {
// 你程序的实现细节...
client := hubs.NewGroupClient("<YOUR SUBSCRIPTION ID>")
client.Authorizer = // 你初始化的服务主体令牌
results, err := client.Get("<RESOURCE GROUP NAME>", "<NAMESPACE NAME>", "<NOTIFICATION HUB NAME>")
if err != nil {
return
}
}
英文:
@cd1 is correct! The Get method doesn't belong directly to namespace that you've imported, but rather a client that exists in that namespace. In order to interact with NotificationsHub in this manner, instantiate a GroupClient
then run a Get
command.
import (
hubs "github.com/Azure/azure-sdk-for-go/arm/notificationshub"
)
func main() {
// Implementation details of your program ...
client := hubs.NewGroupClient("<YOUR SUBSCRIPTION ID>")
client.Authorizer = // Your initialized Service Principal Token
results, err := client.Get("<RESOURCE GROUP NAME>", "<NAMESPACE NAME>", "<NOTIFICATION HUB NAME>")
if err != nil {
return
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论