[英]Bigquery Golang client get projects list
How can I get a list of projects that the golang cloud client has access to using the serviceaccount key that I have provided? 如何使用我提供的serviceaccount密钥获取golang云客户端可以访问的项目列表? Seems like there is an API available: https://cloud.google.com/bigquery/docs/reference/rest/v2/projects/list
似乎有可用的API: https : //cloud.google.com/bigquery/docs/reference/rest/v2/projects/list
However, the Google Cloud client library does not expose it. 但是,Google Cloud客户端库不会公开它。
My code looks like this 我的代码看起来像这样
client, err := bigquery.NewClient(ctx, conn.ProjectID, option.WithServiceAccountFile(fname))
I want to enumerate the list of projects that this client can access. 我想枚举此客户端可以访问的项目列表。
below example can give you an idea - it is sandboxed go that is part of our BQ UI 下面的示例可以给您一个想法-它是沙盒化流程,是我们BQ UI的一部分
func mainReturn() interface{} {
bigqueryService, err := getBigqueryService() ; if(err != nil) {return "ERROR"}
err2 := getProjects(bigqueryService) ; if(err2 != nil) {return "ERROR"}
return "OK"
}
func getProjects(bigqueryService *bigquery.Service)(error) {
var buf bytes.Buffer
var pagetoken string = ""
ind := 0
for {
call := bigqueryService.Projects.List()
if len(pagetoken) > 0 {call = call.PageToken(pagetoken)}
list, err := call.Do() ; if err != nil {return err}
if len(pagetoken) == 0 {
xFprintf(&buf, "TotalItems: %v\n", list.TotalItems)
}
for _, project := range list.Projects {
xFprintf(&buf, "========= Projects %v ==============\n", ind)
xFprintf(&buf, "Id: %v\n", project.Id)
xFprintf(&buf, "Kind: %v\n", project.Kind)
project := project.Id
del := strings.LastIndex(project, ".")
if del != -1 {project = project[del+1:]}
ind++;
}
pagetoken = list.NextPageToken ; if len(pagetoken) == 0 {break}
}
xPrintln(buf.String())
return nil
}
Please ignore some funny looking functions like xFprintf - this is just way we sandboxed go 请忽略一些有趣的功能,例如xFprintf-这只是我们沙盒化的方式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.