embedded

package
v1.37.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package embedded provides an implementation of an embedded filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToEFSPath added in v1.26.1

func ToEFSPath(path string) string

ToEFSPath converts a native file system path into one used by the EFS.

Types

type EFS

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

EFS holds an embedded filesystem.

func NewEFS

func NewEFS(files map[string]*File) *EFS

NewEFS creates a new embedded filesystem.

func NewEFSFromEmbeddedZip added in v1.4.0

func NewEFSFromEmbeddedZip() (*EFS, error)

NewEFSFromEmbeddedZip creates a new EFS from the contents of a zip file appended to the end of the executable.

func NewEFSFromZip added in v1.4.0

func NewEFSFromZip(zr *zip.Reader) (*EFS, error)

NewEFSFromZip creates a new EFS from the contents of a zip file.

func (*EFS) FileSystem

func (efs *EFS) FileSystem(localRoot string) FileSystem

FileSystem returns either the embedded filesystem or a live filesystem rooted at localRoot if localRoot isn't an empty string and points to a directory.

func (*EFS) PrimaryFileSystem added in v1.4.0

func (efs *EFS) PrimaryFileSystem() FileSystem

PrimaryFileSystem returns the primary filesystem this EFS represents.

type File

type File struct {
	*bytes.Reader
	// contains filtered or unexported fields
}

File holds the data for an embedded file.

func NewFile

func NewFile(name string, modTime time.Time, size int64, compressed bool, data []byte) *File

NewFile creates a new embedded file.

func (*File) Close

func (f *File) Close() error

Close the file. Does nothing and always returns nil. Implements the io.Closer interface.

func (*File) IsDir

func (f *File) IsDir() bool

IsDir returns true if this represents a directory. Implements the os.FileInfo interface.

func (*File) ModTime

func (f *File) ModTime() time.Time

ModTime returns the file modification time. Implements the os.FileInfo interface.

func (*File) Mode

func (f *File) Mode() os.FileMode

Mode returns the file mode bits. Implements the os.FileInfo interface.

func (*File) Name

func (f *File) Name() string

Name returns the base name of the file. Implements the os.FileInfo interface.

func (*File) Readdir

func (f *File) Readdir(count int) ([]os.FileInfo, error)

Readdir reads a directory and returns information about its contents. Implements the http.File interface.

func (*File) Size

func (f *File) Size() int64

Size returns the size of the file in bytes. Implements the os.FileInfo interface.

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat returns information about the file. Implements the http.File interface.

func (*File) Sys

func (f *File) Sys() interface{}

Sys returns nil. Implements the os.FileInfo interface.

type FileSystem

type FileSystem interface {
	http.FileSystem
	IsLive() bool
	ContentAsBytes(path string) ([]byte, bool)
	MustContentAsBytes(path string) []byte
	ContentAsString(path string) (string, bool)
	MustContentAsString(path string) string
}

FileSystem defines the methods available for a live or embedded filesystem.

func NewFileSystemFromEmbeddedZip added in v1.4.0

func NewFileSystemFromEmbeddedZip(fallbackLiveFSRoot string) FileSystem

NewFileSystemFromEmbeddedZip creates a new FileSystem from the contents of a zip file appended to the end of the executable. If no such data can be found, then 'fallbackLiveFSRoot' is used to return a FileSystem based upon the local disk.

To create an embedded zip file, first create your zip file as normal, e.g. `zip -9 -r path/to/zip_file path/to/zip`. Build your executable as normal, e.g. `go build -o path/to/exe main.go`, then concatenate the zip file to the end of your executable, e.g. `cat path/to/zip_file >> path/to/exe`. Finally, run `zip -A path/to/exe` on your executable to fix up the offsets.

func NewLiveFS added in v1.4.0

func NewLiveFS(localRoot string) FileSystem

NewLiveFS creates a new live filesystem with a root at the specified location on the regular filesystem.

func NewSubFileSystem added in v1.5.0

func NewSubFileSystem(parent FileSystem, base string) FileSystem

NewSubFileSystem creates a new FileSystem rooted at 'base' within an existing FileSystem.

type LayeredFS added in v1.2.0

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

LayeredFS holds the contents of a layered file system.

func NewLayeredFS added in v1.2.0

func NewLayeredFS(primary string, primaries map[string]FileSystem, fallback FileSystem) *LayeredFS

NewLayeredFS creates a composite FileSystem. Multiple file systems may be designated as the potential primary and are chosen between dynamically at the time of a request by the current value of primary. Should the primary file system be unable to fulfill the request, then the request is passed to the fallback file system.

func (*LayeredFS) ContentAsBytes added in v1.2.0

func (fs *LayeredFS) ContentAsBytes(path string) ([]byte, bool)

ContentAsBytes returns the file contents as bytes

func (*LayeredFS) ContentAsString added in v1.2.0

func (fs *LayeredFS) ContentAsString(path string) (string, bool)

ContentAsString returns the file contents a string

func (*LayeredFS) IsLive added in v1.2.0

func (fs *LayeredFS) IsLive() bool

IsLive returns true if the underlying filesystem is considered to be "live"

func (*LayeredFS) MustContentAsBytes added in v1.2.0

func (fs *LayeredFS) MustContentAsBytes(path string) []byte

MustContentAsBytes returns the file contents as bytes, exiting if unable to

func (*LayeredFS) MustContentAsString added in v1.2.0

func (fs *LayeredFS) MustContentAsString(path string) string

MustContentAsString returns the file contents as a string, exiting if unable to

func (*LayeredFS) Open added in v1.2.0

func (fs *LayeredFS) Open(name string) (http.File, error)

Open a file

func (*LayeredFS) SetPrimary added in v1.2.0

func (fs *LayeredFS) SetPrimary(primary string)

SetPrimary sets the primary filesystem

Directories

Path Synopsis
Package htmltmpl provides convenience utilities for using html templates in an embedded filesystem.
Package htmltmpl provides convenience utilities for using html templates in an embedded filesystem.
Package texttmpl provides convenience utilities for using text templates in an embedded filesystem.
Package texttmpl provides convenience utilities for using text templates in an embedded filesystem.

Jump to

Keyboard shortcuts

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