githubfs

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 9 Imported by: 1

README

Go GitHub filesystem

GitHub Workflow Status go.dev reference GitHub go.mod Go version OpenSSF Scorecard

Go fs.FS implementation for the GitHub Contents API

Installation

go get github.com/sagikazarmark/go-github-fs

Usage

package main

import (
	"github.com/google/go-github/v74/github"
	"github.com/sagikazarmark/go-github-fs"
)

func main() {
	client := github.NewClient(nil)

	fsys := githubfs.New(githubfs.WithClient(client))

	file, err := fsys.Open("sagikazarmark/go-github-fs/README.md")
	if err != nil {
		panic(err)
	}
	defer file.Close()

	_ = file
}

Check out the documentation for all options.

License

The project is licensed under the MIT License.

Documentation

Overview

Package githubfs provides an fs.FS implementation for GitHub repositories using the GitHub API.

Example
package main

import (
	"bufio"
	"fmt"
	"os"

	"github.com/google/go-github/v74/github"

	githubfs "github.com/sagikazarmark/go-github-fs"
)

func main() {
	client := github.NewClient(nil)

	if token := os.Getenv("GITHUB_TOKEN"); token != "" {
		client = client.WithAuthToken(token)
	}

	fsys := githubfs.New(githubfs.WithClient(client))

	file, err := fsys.Open("sagikazarmark/locafero/README.md")
	if err != nil {
		panic(err)
	}
	defer file.Close()

	scanner := bufio.NewScanner(file)
	scanner.Scan()

	fmt.Println(scanner.Text())

}
Output:

# Finder library for [Afero](https://github.com/spf13/afero)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) fs.FS

New creates a new GitHub filesystem for the specified repository.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

ClientOption configures the filesystem using the functional options paradigm popularized by Rob Pike and Dave Cheney.

If you're unfamiliar with this style, check out the following articles:

func WithClient

func WithClient(c *github.Client) Option

WithClient configures a github.Client.

func WithContext

func WithContext(ctx context.Context) Option

WithContext configures a context.Context.

func WithContextFunc

func WithContextFunc(fn func(context.Context) context.Context) Option

WithContextFunc configures a function that creates a new context for each request.

func WithOwner

func WithOwner(owner string) Option

WithOwner configures the owner.

func WithRepository

func WithRepository(owner string, repo string) Option

WithRepository configures the repository.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL