|
| 1 | +// Copyright 2016 The go-github AUTHORS. All rights reserved. |
| 2 | +// |
| 3 | +// Use of this source code is governed by a BSD-style |
| 4 | +// license that can be found in the LICENSE file. |
| 5 | + |
| 6 | +package github_test |
| 7 | + |
| 8 | +import ( |
| 9 | + "fmt" |
| 10 | + "log" |
| 11 | + |
| 12 | + "github.com/google/go-github/github" |
| 13 | +) |
| 14 | + |
| 15 | +func ExampleClient_Markdown() { |
| 16 | + client := github.NewClient(nil) |
| 17 | + |
| 18 | + input := "# heading #\n\nLink to issue #1" |
| 19 | + opt := &github.MarkdownOptions{Mode: "gfm", Context: "google/go-github"} |
| 20 | + |
| 21 | + output, _, err := client.Markdown(input, opt) |
| 22 | + if err != nil { |
| 23 | + fmt.Println(err) |
| 24 | + } |
| 25 | + |
| 26 | + fmt.Println(output) |
| 27 | +} |
| 28 | + |
| 29 | +func ExampleRepositoriesService_GetReadme() { |
| 30 | + client := github.NewClient(nil) |
| 31 | + |
| 32 | + readme, _, err := client.Repositories.GetReadme("google", "go-github", nil) |
| 33 | + if err != nil { |
| 34 | + fmt.Println(err) |
| 35 | + return |
| 36 | + } |
| 37 | + |
| 38 | + content, err := readme.GetContent() |
| 39 | + if err != nil { |
| 40 | + fmt.Println(err) |
| 41 | + return |
| 42 | + } |
| 43 | + |
| 44 | + fmt.Printf("google/go-github README:\n%v\n", content) |
| 45 | +} |
| 46 | + |
| 47 | +func ExampleRepositoriesService_List() { |
| 48 | + client := github.NewClient(nil) |
| 49 | + |
| 50 | + user := "willnorris" |
| 51 | + opt := &github.RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"} |
| 52 | + |
| 53 | + repos, _, err := client.Repositories.List(user, opt) |
| 54 | + if err != nil { |
| 55 | + fmt.Println(err) |
| 56 | + } |
| 57 | + |
| 58 | + fmt.Printf("Recently updated repositories by %q: %v", user, github.Stringify(repos)) |
| 59 | +} |
| 60 | + |
| 61 | +func ExampleUsersService_ListAll() { |
| 62 | + client := github.NewClient(nil) |
| 63 | + opts := &github.UserListOptions{} |
| 64 | + for { |
| 65 | + users, _, err := client.Users.ListAll(opts) |
| 66 | + if err != nil { |
| 67 | + log.Fatalf("error listing users: %v", err) |
| 68 | + } |
| 69 | + if len(users) == 0 { |
| 70 | + break |
| 71 | + } |
| 72 | + opts.Since = *users[len(users)-1].ID |
| 73 | + // Process users... |
| 74 | + } |
| 75 | +} |
0 commit comments