|
6 | 6 | [](CHANGELOG.md)
|
7 | 7 | [](https://pkg.go.dev/github.com/schmidtw/githubfs)
|
8 | 8 |
|
9 |
| -A go fs.FS based github filesystem. |
| 9 | +A simple to use go fs.FS based github filesystem. |
| 10 | + |
| 11 | +## Resulting Directory Structure |
| 12 | + |
| 13 | +``` |
| 14 | +org_or_user/ // org or username |
| 15 | +└── repository // repository |
| 16 | + ├── git // fixed name 'git' |
| 17 | + │ └── main // the branch name |
| 18 | + │ └── README.md // the files in the repo |
| 19 | + └── releases // fixed name 'releases' |
| 20 | + └── v0.0.1 // release version |
| 21 | + └── description.md // the description of the release and other files from the release |
| 22 | +``` |
| 23 | + |
| 24 | +## Example Usage |
| 25 | + |
| 26 | +```golang |
| 27 | +package githubfs |
| 28 | + |
| 29 | +import ( |
| 30 | + "context" |
| 31 | + "fmt" |
| 32 | + "io/fs" |
| 33 | + "os" |
| 34 | + |
| 35 | + "github.com/schmidtw/githubfs" |
| 36 | + "golang.org/x/oauth2" |
| 37 | +) |
| 38 | + |
| 39 | +func main() { |
| 40 | + src := oauth2.StaticTokenSource( |
| 41 | + &oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")}, |
| 42 | + ) |
| 43 | + httpClient := oauth2.NewClient(context.Background(), src) |
| 44 | + |
| 45 | + gfs := githubfs.New( |
| 46 | + githubfs.WithHttpClient(httpClient), |
| 47 | + githubfs.WithRepo("schmidtw", "githubfs"), |
| 48 | + ) |
| 49 | + |
| 50 | + err := fs.WalkDir(gfs, "schmidtw/githubfs/git/main/.reuse", |
| 51 | + func(path string, d fs.DirEntry, err error) error { |
| 52 | + fmt.Printf("%s\n", path) |
| 53 | + if err != nil || d.IsDir() { |
| 54 | + return err |
| 55 | + } |
| 56 | + |
| 57 | + return nil |
| 58 | + }) |
| 59 | + if err != nil { |
| 60 | + panic(err) |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +## Limitations |
| 66 | + |
| 67 | +- Symlinks are only supported for files fetched for small repos (where the fetch |
| 68 | + occurs via a tarball). |
| 69 | +- Packages are not supported by the graphql API, so they aren't supported here. |
| 70 | +- Gists are not supported presently. |
0 commit comments