From 32a84d13d2c44f6a093a89da754d8a57a399c90f Mon Sep 17 00:00:00 2001 From: Will Norris Date: Thu, 31 Mar 2016 15:15:30 -0700 Subject: [PATCH] move example inline where possible The markdown and repo list examples are pretty simple and can easily be moved to be inline samples so that they render as part of the packages godocs. This helps make them more visible even if they won't run in the browser. The basic auth example requires interacting with the user, so leaving it where it is. Future examples should be included inline whenever possible. --- examples/markdown/main.go | 24 ------------------------ examples/repos/main.go | 33 --------------------------------- github/misc_test.go | 14 ++++++++++++++ github/repos_test.go | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 57 deletions(-) delete mode 100644 examples/markdown/main.go delete mode 100644 examples/repos/main.go diff --git a/examples/markdown/main.go b/examples/markdown/main.go deleted file mode 100644 index ce4e8b1..0000000 --- a/examples/markdown/main.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2014 The go-github AUTHORS. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import ( - "fmt" - - "github.com/google/go-github/github" -) - -func main() { - client := github.NewClient(nil) - - input := "# heading #\nLink to issue #1\n" - md, _, err := client.Markdown(input, &github.MarkdownOptions{Mode: "gfm", Context: "google/go-github"}) - if err != nil { - fmt.Printf("error: %v\n\n", err) - } - - fmt.Printf("converted markdown:\n%v\n", md) -} diff --git a/examples/repos/main.go b/examples/repos/main.go deleted file mode 100644 index b210c8d..0000000 --- a/examples/repos/main.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2013 The go-github AUTHORS. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import ( - "fmt" - - "github.com/google/go-github/github" -) - -func main() { - client := github.NewClient(nil) - - fmt.Println("Recently updated repositories owned by user willnorris:") - - opt := &github.RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"} - repos, _, err := client.Repositories.List("willnorris", opt) - if err != nil { - fmt.Printf("error: %v\n\n", err) - } else { - fmt.Printf("%v\n\n", github.Stringify(repos)) - } - - rate, _, err := client.RateLimits() - if err != nil { - fmt.Printf("Error fetching rate limit: %#v\n\n", err) - } else { - fmt.Printf("API Rate Limit: %#v\n\n", rate) - } -} diff --git a/github/misc_test.go b/github/misc_test.go index 8ca58d2..16c5512 100644 --- a/github/misc_test.go +++ b/github/misc_test.go @@ -46,6 +46,20 @@ func TestMarkdown(t *testing.T) { } } +func ExampleClient_Markdown() { + client := NewClient(nil) + + input := "# heading #\n\nLink to issue #1" + opt := &MarkdownOptions{Mode: "gfm", Context: "google/go-github"} + + output, _, err := client.Markdown(input, opt) + if err != nil { + fmt.Println(err) + } + + fmt.Println(output) +} + func TestListEmojis(t *testing.T) { setup() defer teardown() diff --git a/github/repos_test.go b/github/repos_test.go index 3265149..e875c0e 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -67,6 +67,20 @@ func TestRepositoriesService_List_invalidUser(t *testing.T) { testURLParseError(t, err) } +func ExampleRepositoriesService_List() { + client := NewClient(nil) + + user := "willnorris" + opt := &RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"} + + repos, _, err := client.Repositories.List(user, opt) + if err != nil { + fmt.Println(err) + } + + fmt.Printf("Recently updated repositories by %q: %v", user, Stringify(repos)) +} + func TestRepositoriesService_ListByOrg(t *testing.T) { setup() defer teardown()