如何使用Golang构建特定版本的Github APIv4查询
时间:2024-02-06
浏览:489
作者:佚名
学习知识要善于思考,思考,再思考!今天golang学习网小编就给大家带来《如何使用Golang构建特定版本的Github APIv4查询》,以下内容主要包含等知识点,如果你正在学习或准备学习Golang,就都不要错过本文啦~让我们一起来看看吧,能帮助到你就更好了!
问题内容
使用 https://github.com/shurcooL/githubv4,我真的很难为 gh 存储库拉回特定版本。
当有 v3 版本时,以下代码块始终不返回任何内容:
var releaseQ struct {
Repository struct {
Release struct {
Author githubv4.String
} `graphql:"release(tagName:$tagName)"`
} `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"`
}
variables = map[string]interface{}{
"repositoryOwner": githubv4.String("jacobtomlinson"),
"repositoryName": githubv4.String("gha-find-replace"),
"tagName": githubv4.String("v3"),
}
err = client.Query(context.Background(), &releaseQ, variables)
if err != nil {
fmt.Println("Query returned nothing")
}
fmt.Println("author:", releaseQ.Repository.Release.Author)
我已成功获得以下两个代码块,用于存储库描述和问题反应:
var repoDescriptionQ struct {
Repository struct {
Description string
} `graphql:"repository(owner: \"jacobtomlinson\", name: \"gha-find-replace\")"`
}
此成功返回存储库描述 ^
variables := map[string]interface{}{
"repositoryOwner": githubv4.String("jacobtomlinson"),
"repositoryName": githubv4.String("gha-find-replace"),
"issueNumber": githubv4.Int(55),
"reactionContent": githubv4.ReactionContentThumbsDown,
}
var reactionQ struct {
Repository struct {
Issue struct {
ID githubv4.ID
Reactions struct {
ViewerHasReacted githubv4.Boolean
} `graphql:"reactions(content:$reactionContent)"`
} `graphql:"issue(number:$issueNumber)"`
} `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"`
}
这成功地得到了反应^
正确答案
发现,作者字段不是字符串,而是“User”类型。将请求的字段更改为“描述”,这是一个字符串,它正在拉回发布信息。如果您确实需要作者,则需要定义用户:
var releaseQ struct {
Repository struct {
Release struct {
Description githubv4.String
} `graphql:"release(tagName:$tagName)"`
} `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"`
}以上就是《如何使用Golang构建特定版本的Github APIv4查询》的详细内容,更多关于的资料请关注golang学习网公众号!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
站内热门
最新文章
11.27
11.27
11.27
11.27
热门专题
