asset

package
v0.33.5-rc-monkit Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2020 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package asset implements asset embedding via implementing http.FileSystem interface.

To use the package you would define:

//go:generate go run ../private/asset/generate/main.go -pkg main -dir ../../web/bootstrap -var embeddedAssets -out console.resource.go
var embeddedAssets http.FileSystem

This will generate a new "console.resource.go" which contains the content of "../../web/bootstrap".

In the program initialization you can select based on whether the embedded resources exist or not:

var assets http.FileSystem
if *staticAssetDirectory != "" {
    assets = http.Dir(*staticAssetDirectory)
} else if embeddedAssets == nil {
    assets = embeddedAssets
} else {
    assets = http.Dir(defaultAssetLocation)
}

Then write the service in terms of http.FileSystem, which hides the actual thing used for loading.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	Name     string
	Mode     os.FileMode
	ModTime  time.Time
	Data     []byte
	Children []*Asset
}

Asset describes a tree of asset files and directories.

func ReadDir

func ReadDir(path string) (*Asset, error)

ReadDir loads an asset directory from filesystem.

func ReadFile

func ReadFile(path string) (*Asset, error)

ReadFile loads an asset from filesystem.

func (*Asset) File

func (asset *Asset) File() *File

File opens the particular asset as a file.

func (*Asset) InmemoryCode

func (asset *Asset) InmemoryCode() []byte

InmemoryCode generates a function closure []byte that can be assigned to a variable.

type File

type File struct {
	bytes.Reader
	*Asset
}

File defines a readable file

func (*File) Close

func (file *File) Close() error

Close closes the file.

func (*File) Readdir

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

Readdir reads all file infos from the directory.

func (*File) Stat

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

Stat returns stats about the file.

type FileInfo

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

FileInfo implements file info.

func (FileInfo) IsDir

func (info FileInfo) IsDir() bool

IsDir implements os.FileInfo

func (FileInfo) ModTime

func (info FileInfo) ModTime() time.Time

ModTime implements os.FileInfo

func (FileInfo) Mode

func (info FileInfo) Mode() os.FileMode

Mode implements os.FileInfo

func (FileInfo) Name

func (info FileInfo) Name() string

Name implements os.FileInfo

func (FileInfo) Size

func (info FileInfo) Size() int64

Size implements os.FileInfo

func (FileInfo) Sys

func (info FileInfo) Sys() interface{}

Sys implements os.FileInfo

type InmemoryFileSystem

type InmemoryFileSystem struct {
	Root  *Asset
	Index map[string]*Asset
}

InmemoryFileSystem defines an inmemory http.FileSystem

func Inmemory

func Inmemory(root *Asset) *InmemoryFileSystem

Inmemory creates an InmemoryFileSystem from

func (*InmemoryFileSystem) Open

func (fs *InmemoryFileSystem) Open(path string) (http.File, error)

Open opens the file at the specified path.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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