maintner: add examples
Demonstrate how to load data from a network source and how to load
data from a local disk source.
Change-Id: I1710eca8a1b3be7b7f7458de6aa5d3372934450a
Reviewed-on: https://go-review.googlesource.com/84377
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/maintner/example_test.go b/maintner/example_test.go
new file mode 100644
index 0000000..a5351b5
--- /dev/null
+++ b/maintner/example_test.go
@@ -0,0 +1,59 @@
+// Copyright 2017 The Go 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 maintner_test
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "os"
+ "path/filepath"
+
+ "golang.org/x/build/maintner"
+)
+
+func Example() {
+ cacheDir := filepath.Join(os.Getenv("HOME"), "var", "maintnerd")
+ // maintner.golang.org contains the metadata for the Go project and related
+ // Github repositories and issues.
+ mutSrc := maintner.NewNetworkMutationSource("https://maintner.golang.org/logs", cacheDir)
+ corpus := new(maintner.Corpus)
+ if err := corpus.Initialize(context.Background(), mutSrc); err != nil {
+ log.Fatal(err)
+ }
+ err := corpus.GitHub().ForeachRepo(func(r *maintner.GitHubRepo) error {
+ fmt.Println(r.ID())
+ return nil
+ })
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
+func Example_fromDisk() {
+ logger := maintner.NewDiskMutationLogger(filepath.Join(os.Getenv("HOME"), "var", "maintnerd"))
+ corpus := new(maintner.Corpus)
+ corpus.Initialize(context.Background(), logger)
+ err := corpus.GitHub().ForeachRepo(func(r *maintner.GitHubRepo) error {
+ fmt.Println(r.ID())
+ return nil
+ })
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
+func ExampleDiskMutationLogger() {
+ logger := maintner.NewDiskMutationLogger(filepath.Join(os.Getenv("HOME"), "var", "maintnerd"))
+ corpus := new(maintner.Corpus)
+ corpus.Initialize(context.Background(), logger)
+ err := corpus.GitHub().ForeachRepo(func(r *maintner.GitHubRepo) error {
+ fmt.Println(r.ID())
+ return nil
+ })
+ if err != nil {
+ log.Fatal(err)
+ }
+}