site

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package site holds binary resources embedded into Go executable

Index

Constants

This section is empty.

Variables

View Source
var ServeHTTP = HTTPHandlerWithPrefix("")

ServeHTTP provides a convenience handler whenever embedded content should be served from the root URI.

Functions

func CopyTo added in v1.1.0

func CopyTo(target string, mode os.FileMode, overwrite bool, files ...string) error

The CopyTo method extracts all mentioned files to a specified location, keeping directory structure. If supplied file is a directory, than it will be extracted recursively. CopyTo with no file mentioned will extract the whole content of the embedded filesystem. CopyTo returns error if there is a file with the same name at the target location, unless overwrite is set to true, or file has the same size and modification file as the extracted file. site.CopyTo(".", mode, false) will effectively extract content of the filesystem to the current directory (which makes it the most space-wise inefficient self-extracting archive ever).

func HTTPHandlerWithPrefix

func HTTPHandlerWithPrefix(prefix string) func(http.ResponseWriter, *http.Request)

HTTPHandlerWithPrefix provides a simple way to serve embedded content via Go standard HTTP server and returns an http handler function. The "prefix" will be stripped from the request URL to serve embedded content from non-root URI

func HttpFileSystem

func HttpFileSystem() http.FileSystem

Types

type Asset

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

Asset represents binary resource stored within Go executable. Asset implements fmt.Stringer and io.WriterTo interfaces, decompressing binary data if necessary.

func Get

func Get(name string) *Asset

Gets asset by name. Returns nil if no asset found.

func Must

func Must(name string) *Asset

Get asset by name. Panics if no asset found.

func (*Asset) Bytes added in v1.1.0

func (a *Asset) Bytes() []byte

Bytes returns (uncompressed) content of asset as a []byte

func (*Asset) IsCompressed

func (a *Asset) IsCompressed() bool

IsCompressed returns true of asset has been compressed

func (*Asset) IsDir

func (a *Asset) IsDir() bool

IsDir implements os.FileInfo and returns false

func (*Asset) MimeType

func (a *Asset) MimeType() string

MimeType returns MIME Type of the asset

func (*Asset) ModTime

func (a *Asset) ModTime() time.Time

ModTime implements os.FileInfo and returns the time stamp when this package has been produced (the same value for all the assets)

func (*Asset) Mode

func (a *Asset) Mode() os.FileMode

Mode implements os.FileInfo and always returns 0444

func (*Asset) Name

func (a *Asset) Name() string

Name returns the base name of the asset

func (*Asset) RawBytes added in v1.1.0

func (a *Asset) RawBytes() []byte

RawBytes returns a raw byte slice of the asset. Changing content of slice will result into segfault.

func (*Asset) Reader added in v1.1.0

func (a *Asset) Reader() io.ReadCloser

Returns content of the asset as io.ReaderCloser.

func (*Asset) Size

func (a *Asset) Size() int64

Size implements os.FileInfo and returns the size of the asset (uncompressed, if asset has been compressed)

func (*Asset) String

func (a *Asset) String() string

String returns (uncompressed, if necessary) content of asset as a string

func (*Asset) Sys

func (a *Asset) Sys() interface{}

Sys implements os.FileInfo and returns nil

func (*Asset) WriteTo

func (a *Asset) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo interface and writes content of the asset to w

type File

type File interface {
	io.Closer
	io.Reader
	io.Seeker
	Readdir(count int) ([]os.FileInfo, error)
	Stat() (os.FileInfo, error)
}

A File is returned by virtual FileSystem's Open method. The methods should behave the same as those on an *os.File.

func Open

func Open(name string) (File, error)

Opens asset as an io.ReadCloser. Returns os.ErrNotExist if no asset is found.

type FileSystem added in v1.1.0

type FileSystem interface {
	Open(name string) (File, error)
	Stat(name string) (os.FileInfo, error)
	// As in filepath.Walk
	Walk(root string, walkFunc filepath.WalkFunc) error
	// Returns http.FileSystem interface to use with http.Server
	HttpFileSystem() http.FileSystem
}

A simple FileSystem abstraction

func FS added in v1.1.0

func FS() FileSystem

Returns embedded FileSystem

func NewUnionFS added in v1.1.0

func NewUnionFS(src string) (FileSystem, error)

Jump to

Keyboard shortcuts

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