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.

图片转代码服务由CSDN问答提供 功能建议

Am试图使用Go Azure SDK调用通知中心api

我已经安装了SDK并导入了GO文件:

 程序包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(“发生错误”)
返回
} 
 fmt.Println(“成功”)
 
} 
   
 \  n 

但是,当我尝试运行他的代码时,出现此错误

 未定义:notificationhubs.Get 
   
 
 <  p>也不知道这是什么意思,因为我的IDE不会抱怨导入Azure SDK,因此假设SDK已正确导入。 
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 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 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
        }
    }
    
    打赏 评论

相关推荐 更多相似问题