golang.org/x/build@v0.0.0-20240506185731-218518f32b70/maintner/example_test.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package maintner_test 6 7 import ( 8 "context" 9 "fmt" 10 "log" 11 "os" 12 "path/filepath" 13 14 "golang.org/x/build/maintner" 15 ) 16 17 func Example() { 18 cacheDir := filepath.Join(os.Getenv("HOME"), "var", "maintnerd") 19 // maintner.golang.org contains the metadata for the Go project and related 20 // Github repositories and issues. 21 mutSrc := maintner.NewNetworkMutationSource("https://maintner.golang.org/logs", cacheDir) 22 corpus := new(maintner.Corpus) 23 if err := corpus.Initialize(context.Background(), mutSrc); err != nil { 24 log.Fatal(err) 25 } 26 err := corpus.GitHub().ForeachRepo(func(r *maintner.GitHubRepo) error { 27 fmt.Println(r.ID()) 28 return nil 29 }) 30 if err != nil { 31 log.Fatal(err) 32 } 33 } 34 35 func Example_fromDisk() { 36 logger := maintner.NewDiskMutationLogger(filepath.Join(os.Getenv("HOME"), "var", "maintnerd")) 37 corpus := new(maintner.Corpus) 38 corpus.Initialize(context.Background(), logger) 39 err := corpus.GitHub().ForeachRepo(func(r *maintner.GitHubRepo) error { 40 fmt.Println(r.ID()) 41 return nil 42 }) 43 if err != nil { 44 log.Fatal(err) 45 } 46 } 47 48 func ExampleDiskMutationLogger() { 49 logger := maintner.NewDiskMutationLogger(filepath.Join(os.Getenv("HOME"), "var", "maintnerd")) 50 corpus := new(maintner.Corpus) 51 corpus.Initialize(context.Background(), logger) 52 err := corpus.GitHub().ForeachRepo(func(r *maintner.GitHubRepo) error { 53 fmt.Println(r.ID()) 54 return nil 55 }) 56 if err != nil { 57 log.Fatal(err) 58 } 59 }