drb0901500211
drb0901500211
2017-06-05 12:21
浏览 76
已采纳

Go + Azure:调用方法返回未定义

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douying4203
    douying4203 2017-06-05 19:09
    已采纳

    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.

    点赞 评论
  • dongliao6777
    dongliao6777 2017-06-07 17:38

    @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
        }
    }
    
    点赞 评论

相关推荐