Browse Source

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.
Will Norris 10 years ago
parent
commit
32a84d13d2
4 changed files with 28 additions and 57 deletions
  1. +0
    -24
      examples/markdown/main.go
  2. +0
    -33
      examples/repos/main.go
  3. +14
    -0
      github/misc_test.go
  4. +14
    -0
      github/repos_test.go

+ 0
- 24
examples/markdown/main.go View File

@ -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)
}

+ 0
- 33
examples/repos/main.go View File

@ -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)
}
}

+ 14
- 0
github/misc_test.go View File

@ -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()


+ 14
- 0
github/repos_test.go View File

@ -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()


Loading…
Cancel
Save