-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
54 lines (44 loc) · 1.16 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-FileCopyrightText: 2022 Weston Schmidt <[email protected]>
// SPDX-License-Identifier: Apache-2.0
package githubfs_test
import (
"context"
"fmt"
"io/fs"
"os"
"github.com/schmidtw/githubfs"
"golang.org/x/oauth2"
)
func Example() {
token := os.Getenv("GITHUB_TOKEN")
// Github requires credentials to use the v4 API. Bypass this in the
// tests to prevent false failures, but enable folks to easily try out
// the feature.
if len(token) == 0 {
fmt.Println("schmidtw/githubfs/git/main/.reuse")
fmt.Println("schmidtw/githubfs/git/main/.reuse/dep5")
return
}
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
httpClient := oauth2.NewClient(context.Background(), src)
gfs := githubfs.New(
githubfs.WithHttpClient(httpClient),
githubfs.WithRepo("schmidtw", "githubfs"),
)
err := fs.WalkDir(gfs, "schmidtw/githubfs/git/main/.reuse",
func(path string, d fs.DirEntry, err error) error {
fmt.Printf("%s\n", path)
if err != nil || d.IsDir() {
return err
}
return nil
})
if err != nil {
panic(err)
}
// Output:
// schmidtw/githubfs/git/main/.reuse
// schmidtw/githubfs/git/main/.reuse/dep5
}