modulepackage
0.0.0-20230611201613-116bc6be5006
Repository: https://github.com/schmidtw/githubfs.git
Documentation: pkg.go.dev
# README
githubfs
A simple to use go fs.FS based github filesystem.
Resulting Directory Structure
org_or_user/ // org or username
└── repository // repository
├── git // fixed name 'git'
│ └── main // the branch name
│ └── README.md // the files in the repo
└── releases // fixed name 'releases'
└── v0.0.1 // release version
└── description.md // the description of the release and other files from the release
Example Usage
package githubfs
import (
"context"
"fmt"
"io/fs"
"os"
"github.com/schmidtw/githubfs"
"golang.org/x/oauth2"
)
func main() {
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_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)
}
}
Limitations
- Symlinks are only supported for files fetched for small repos (where the fetch occurs via a tarball).
- Packages are not supported by the github graphql API, so they aren't supported here.
- Gists are not supported presently.
# Functions
New creates a new githubfs.FS object with the specified configuration.
WithGithubEnterprise specifies the API version to support for backwards compatibility.
WithHttpClient provides a way to set the HTTP client to use.
WithOrg instructs the filesystem to include all the repositories owned by an organization or user and the default branches of each repo.
WithRepo configures a specific owner, repository and branches to include.
WithSlug provides a way to easily configure a set of repos, or unique repo based on the slug string.
WithSlugs provides a way to pass in an array of slugs and it will take care of the rest.
WithThresholdInKB sets the maximum size to download the entire repository vs.
# Type aliases
Option is the type used for options.