overlay

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: MIT Imports: 3 Imported by: 1

README

Overlay

Go Reference

Overlay File System

Overlay is an easy way to implement a file system in such a way that production assets can be overridden by assets on disk.

Usage

package main

import (
	"embed"
	
	"go.jolheiser.com/overlay"
)

//go:embed assets
var assets embed.FS

func main() {
	ofs, err := overlay.New("/var/lib/myapp/custom", assets)
	if err != nil {
		panic(err)
    }
    ...
}

If /var/lib/myapp/custom has an assets sub-directory, this implementation works.

However, if /var/lib/myapp/custom matches the assets directory layout, you can use WithSub like so...

package main

import (
	"embed"
	
	"go.jolheiser.com/overlay"
)

//go:embed assets
var assets embed.FS

func main() {
	ofs, err := overlay.New("/var/lib/myapp/custom", assets, overlay.WithSub("assets"))
	if err != nil {
		panic(err)
    }
    ...
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

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

FS is an overlay File System

func MustNew added in v0.0.3

func MustNew(root string, fs fs.FS, opts ...Option) *FS

MustNew returns New and panics on error

func New

func New(root string, fs fs.FS, opts ...Option) (*FS, error)

New returns a new FS

func (*FS) Open

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

Open opens an fs.File, preferring disk

func (*FS) ReadDir added in v0.0.2

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

ReadDir reads []fs.DirEntry This method will prefer EMBEDDED, because that is the "real" FS for overlay

func (*FS) ReadFile added in v0.0.3

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

ReadFile reads a file, preferring disk

type Option

type Option func(*FS) error

Option is a functional option for an FS

func WithCaching

func WithCaching(doCache bool) Option

WithCaching sets a caching mode for an FS Caching avoids subsequent os.Stat to determine if a file exists on disk See bench.txt for differences in usage

func WithSub

func WithSub(sub string) Option

WithSub sets a fs.Sub for an FS

Jump to

Keyboard shortcuts

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