在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
go-giteego-gitee is a Go client library for accessing the [Gitee API v5][]. go-gitee requires Go version 1.7 or greater. UsageThe go-gitee library does not directly handle authentication. Instead, whencreating a new client, pass an import "golang.org/x/oauth2"import "github.com/weilaihui/go-gitee/gitee"ctx := context.Background()conf := &oauth2.Config{ ClientID: "{ClientID}", ClientSecret: "{ClientSecret}", Scopes: "{Scopes}", Endpoint: oauth2.Endpoint{ AuthURL: "https://gitee.com/oauth/auth", TokenURL: "https://gitee.com/oauth/token", },}token,err := conf.PasswordCredentialsToken(ctx,"{username}","{password}")tp := gitee.OAuthTransport{ Token: token,}client := gitee.NewClient(tp.Client())user, _, err := client.Users.Get(ctx, "")if err != nil { fmt.Printf("\nerror: %v\n", err) return}fmt.Printf("\n%v\n", gitee.Stringify(user))fmt.Printf("\n%v\n", *user.Login) The services of a client divide the API into logical chunks and correspond tothe structure of the Gitee API documentation athttps://gitee.com/api/v5/swagger. Accepted StatusSome endpoints may return a 202 Accepted status code, meaning that theinformation required is not yet ready and was scheduled to be gathered onthe GitHub side. Methods known to behave like this are documented specifyingthis behavior. To detect this condition of error, you can check if its type is stats, _, err := client.Repositories.ListContributorsStats(ctx, org, repo)if _, ok := err.(*gitee.AcceptedError); ok { log.Println("scheduled on Gitee side")} Creating and Updating ResourcesAll structs for Gitee resources use pointer values for all non-repeated fields.This allows distinguishing between unset fields and those set to a zero-value.Helper functions have been provided to easily create these pointers for string,bool, and int values. For example: // create a new private repository named "foo"repo := &gitee.Repository{ Name: gitee.String("foo"), Private: gitee.Bool(true),}client.Repositories.Create(ctx, "", repo) Users who have worked with protocol buffers should find this pattern familiar. PaginationAll requests for resource collections (repos, pull requests, issues, etc.)support pagination. Pagination options are described in the client := gitee.NewClient(nil)opt := &gitee.RepositoryListByOrgOptions{ ListOptions: gitee.ListOptions{PerPage: 10},}// get all pages of resultsvar allRepos []*gitee.Repositoryfor { repos, resp, err := client.Repositories.ListByOrg(ctx, "gitee", opt) if err != nil { return err } allRepos = append(allRepos, repos...) if resp.NextPage == 0 { break } opt.Page = resp.NextPage} For complete usage of go-gitee, see the full package docs. Integration TestsYou can run integration tests from the RoadmapThis library is being initially developed by go-github,so API methods will likely be implemented like go-github.You can track the status of implementation ingo-github. Eventually, I would like to cover the entireGitee API, so contributions are of course always welcome. Thecalling pattern is pretty well established, so adding new methods is relativelystraightforward. LicenseThis library is distributed under the BSD-style license found in the LICENSEfile. |
请发表评论