8000 GitHub - dkumor/revhttpfs: Use an http.FileSystem as an afero.Fs
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

dkumor/revhttpfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RevHttpFs

The afero golang library already has an afero.HttpFs which goes from an afero Fs to http.FileSystem. This package implements the reverse, allowing use of an http.FileSystem as an afero.Fs.

Motivation

The reason for this is that many tools expose http.FileSystem interfaces, since it is the standard in golang for serving files.

In particular, tools to embed files in golang executables usually return http.FileSystems (see statik, packr, vfsgen, etc).

Allowing to use these with Afero leads to some really useful stuff, such as using afero.CopyOnWriteFs to "overlay" a configuration folder/memory map over the http.FileSystem returned from such tools.

Example

import (

    "github.com/rakyll/statik/fs"
    "github.com/spf13/afero"
    "github.com/dkumor/revhttpfs"
)

func OverwritableBuiltinFileSystem() (afero.Fs,error) {
    statikFS, err := fs.New()
    if err!=nil {
        return nil,err
    }

    aferoStatikFs := revhttpfs.NewReverseHttpFs(statikFS)
    overwritableStatikFs := afero.NewMemMapFs()

    return afero.NewCopyOnWriteFs(aferoStatikFs, pluginFs),nil
}

The above code uses resources embedded in the executable with statik, which come in the form of an http.FileSystem, uses ReverseHttpFs to convert it to an afero.Fs, and then creates a copy-on-write overlay over the static built-in files, using a memory map.

About

Use an http.FileSystem as an afero.Fs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0