如何构建特定版本的 Github APIv4 Golang 查询

如何构建特定版本的 github apiv4 golang 查询

php小编柚子将为大家介绍如何构建特定版本的 Github APIv4 Golang 查询的方法。Github APIv4是一个强大的查询工具,可以帮助开发者获取并处理Github上的各种数据。然而,有时候我们可能需要获取特定版本的数据,而官方API并没有直接提供这样的功能。在本文中,我们将探讨如何使用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)

登录后复制

我已成功获得以下两个代码块,用于存储库描述和问题反应:

立即学习“go语言免费学习笔记(深入)”;

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)"`}

登录后复制

以上就是如何构建特定版本的 Github APIv4 Golang 查询的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2353963.html

(0)
上一篇 2025年3月1日 14:34:09
下一篇 2025年3月1日 14:34:22

AD推荐 黄金广告位招租... 更多推荐

相关推荐

发表回复

登录后才能评论