ghfs

package module
v0.0.0-...-0068783 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 7 Imported by: 1

README

ghfs

ci Go Reference codecov Go Report Card

Package ghfs wraps the github v3 rest api with io/fs. Files in the repository can be read in the same way as local files.

Example

package ghfs_test

import (
	"context"
	"io"
	"os"

	"github.com/johejo/ghfs"
	"golang.org/x/oauth2"
)

func Example() {
	ctx := context.Background()
	ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")})
	c := oauth2.NewClient(ctx, ts)

	fsys := ghfs.New(c, "golang", "go")
	f, err := fsys.Open("README.md")
	if err != nil {
		panic(err)
	}
	io.Copy(os.Stdout, f)
}

License

MIT

Author

Mitsuo Heijo

Documentation

Overview

Package ghfs wraps the github v3 rest api with io/fs. Files in the repository can be read in the same way as local files.

Example
package main

import (
	"context"
	"io"
	"os"

	"github.com/johejo/ghfs"
	"golang.org/x/oauth2"
)

func main() {
	ctx := context.Background()
	ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")})
	c := oauth2.NewClient(ctx, ts)

	fsys := ghfs.New(c, "golang", "go")
	f, err := fsys.Open("README.md")
	if err != nil {
		panic(err)
	}
	io.Copy(os.Stdout, f)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(c *http.Client, owner, repo string) fs.FS

New returns a new github file sytem.

func NewWithGitHubClient

func NewWithGitHubClient(c *github.Client, owner, repo string) fs.FS

NewWithGitHubClient returns a new github file sytem with *github.Client.

Types

type FS

type FS struct {
	// contains filtered or unexported fields
}

FS is a file system using github v3 reset api. ref: https://docs.github.com/en/rest/reference/repos#get-repository-content

func (*FS) Open

func (f *FS) Open(name string) (fs.File, error)

Open implementes fs.FS and opens a new file asd fs.File.

func (*FS) ReadDir

func (f *FS) ReadDir(name string) ([]fs.DirEntry, error)

ReadFile implementes fs.ReadDirFS.

func (*FS) ReadFile

func (f *FS) ReadFile(name string) ([]byte, error)

ReadFile implementes fs.ReadFileFS.

Jump to

Keyboard shortcuts

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