• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 4 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Go io/fs filesystem implementation for reading files in Github gists.

GistFS

GistFS is an io/fs implementation that enables to read files stored in a given Gist.

Requirements

This module depends on io/fs which is only available since go 1.16.

Usage

GistFS is threadsafe.

package main

import (
	"context"
	"fmt"
	"net/http"

	"github.com/jhchabran/gistfs"
)

func main() {
	// create a FS based on https://gist.github.com/jhchabran/ded2f6727d98e6b0095e62a7813aa7cf
	gfs := gistfs.New("ded2f6727d98e6b0095e62a7813aa7cf")

	// load the remote content once for all,
	// ie, no more API calls toward Github will be made.
	err := gfs.Load(context.Background())
	if err != nil {
		panic(err)
	}

	// --- base API
	// open the "test1.txt" file
	f, err := gfs.Open("test1.txt")
	if err != nil {
		panic(err)
	}

	// read its content
	b := make([]byte, 1024)
	_, err = f.Read(b)

	if err != nil {
		panic(err)
	}

	fmt.Println(string(b))

	// --- ReadFile API
	// directly read the "test1.txt" file
	b, err = gfs.ReadFile("test1.txt")
	if err != nil {
		panic(err)
	}

	fmt.Println(string(b))

	// --- ReadDir API
	// there is only one directory in a gistfile, the root dir "."
	files, err := gfs.ReadDir(".")
	if err != nil {
		panic(err)
	}

	for _, entry := range files {
		fmt.Println(entry.Name())
	}

	// --- Serve the files from the gists over http
	http.ListenAndServe(":8080", http.FileServer(http.FS(gfs)))
}

See also

More Repositories

1

code-search-blocklist

A list of domains hosting scrapped code snippets and polluting search results to block.
31
star
2

tabswitcher

Textmate's Command-T to switch tabs in Google Chrome
Clojure
30
star
3

nvim-config

nvim 0.8 config written in Fennel
Fennel
22
star
4

awesome-devx

A curated list of awesome DevX resources
Go
10
star
5

tabloid

A simple and minimalist Hackernews like engine written in Go.
Go
7
star
6

dotfiles

Personal dotfiles : kitty+ neovim + qutebrowser
Shell
4
star
7

errcheckstack

Go
4
star
8

old-vimfiles

My personal vimfiles, all batteries included !
Vim Script
3
star
9

vim-pigraph

Repackaged Pigraph for pathogen
2
star
10

retrotube

Clojure
2
star
11

doom-monarized-theme

A monochrome variation of Solarized for Doom emacs.
Emacs Lisp
2
star
12

old-dotfiles

My dotfiles
Shell
2
star
13

acts_as_visitable

Rails plugin to track what users ( or any model ) have "seen" another model
Ruby
2
star
14

photograph-service

Minimal web service that wraps around Photograph to take screenshots of web pages.
Ruby
2
star
15

around-the-code-checklist

A list of concepts, tools, domains to learn to become a better developer.
1
star
16

dbms-funcs-scraper

Quick and dirty script to build a JSON dump of all functions from Posgres, MySQL and SQLite.
Go
1
star
17

emacs.d

Emacs + evil config (oriented toward vim users)
Emacs Lisp
1
star
18

sunspot_ar

Sunspot ActiveRecord driver extracted from Sunspot Rails ( so you can use it in Sinatra ).
Ruby
1
star
19

address_book

Fetch *valid* addresses around somewhere ( so you can use them on your gmap )
Ruby
1
star
20

csv2alfredsnippets

Convert CSV describing snippets to Alfred snippets format
Go
1
star
21

activeadmin-paperclip

Provides helpers for ActiveAdmin that assume the use of Paperclip for images.
Ruby
1
star
22

mplayer_screenshot

Grab png screenshots of any video readable using MPlayer
Ruby
1
star
23

jhchabran.github.com

My personal homepage.
HTML
1
star