如何从应用程序调用谷歌云身份API
我正在尝试从我的基于 Go 的应用程序调用 google cloud [groupsmemberships api][1]。我查看了 go [此处的文档][2] 中的文档,但我不确定如何编写简单的代码来在 go 中执行此操作。
这是我尝试写的:
package main
import (
"context"
"google.golang.org/api/cloudidentity/v1beta1"
)
func main() {
ctx := context.Background()
cloudidentityService, err := cloudidentity.NewService(ctx)
res, err := cloudidentity.groups.memberships.lookup('placeholder-value', 'memberKey.namespace')
}
运行此程序时,我收到错误“无法引用未导出的名称 cloudidentity.groups”
我是 Google 云和 golang 的新手。我的任务是查找用户是否属于谷歌云中给定组的一部分。 [1]:https://cloud.google.com/身份/docs/reference/rest/v1beta1/groups.memberships [2]: https://pkg.go.dev/ google.golang.org/api/cloudidentity/v1beta1#GroupsMembershipsLookupCall
I am trying to call google cloud [groups memberships apis][1] from my go based application. I looked at the documentation in go [document here][2] but I am not sure how to write a simple code to do that in go.
here is what I tried to write:
package main
import (
"context"
"google.golang.org/api/cloudidentity/v1beta1"
)
func main() {
ctx := context.Background()
cloudidentityService, err := cloudidentity.NewService(ctx)
res, err := cloudidentity.groups.memberships.lookup('placeholder-value', 'memberKey.namespace')
}
On running this i get error "cannot refer to unexported name cloudidentity.groups"
I am new to Google cloud as well as golang. My task is to find if the user is part of a given group in google cloud.
[1]: https://cloud.google.com/identity/docs/reference/rest/v1beta1/groups.memberships
[2]: https://pkg.go.dev/google.golang.org/api/cloudidentity/v1beta1#GroupsMembershipsLookupCall
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Go 中,如果名称以大写字母开头,则会被导出。 这意味着任何方法您从导入的包调用必须由这些包导出,因此必须以大写字母开头。这应该可以解决您的问题。 之间的区别
.Groups.Memberships.Lookup
.groups.memberships.lookup
In Go, a name is exported if it begins with a capital letter. This means that any methods you call from imported packages must be exported by those packages and therefore must start with capital letters. This should resolve your problem. Note the difference between
.Groups.Memberships.Lookup
.groups.memberships.lookup