Documentation
¶
Index ¶
- Variables
- func AddResource(resource []byte)
- type Bundle
- type Bundler
- type BundlerContext
- type Composer
- type Compressor
- type CompressorConfig
- type CompressorContext
- type Dir
- type Embedder
- type ExecutableFunc
- type File
- type FileSystem
- type FileSystemManager
- type Generator
- type GeneratorConfig
- type Node
- type ReadOnlyFile
- type Resource
- type ResourceFile
- type ResourceFileInfo
- type ResourceManager
- func (m *ResourceManager) Add(resource *Resource) error
- func (m *ResourceManager) Dir(name string) (FileSystemManager, error)
- func (m *ResourceManager) Open(name string) (ReadOnlyFile, error)
- func (m *ResourceManager) OpenFile(name string, flag int, perm os.FileMode) (File, error)
- func (m *ResourceManager) Walk(dir string, fn filepath.WalkFunc) error
- type ResourceManagerConfig
- type ZipCompressor
Constants ¶
This section is empty.
Variables ¶
var ( // ErrReadOnly is returned if the file is read-only and write operations are disabled. ErrReadOnly = errors.New("File is read-only") // ErrWriteOnly is returned if the file is write-only and read operations are disabled. ErrWriteOnly = errors.New("File is write-only") // ErrIsDirectory is returned if the file under operation is not a regular file but a directory. ErrIsDirectory = errors.New("Is directory") )
var ErrSkipResource = fmt.Errorf("Skip Resource Error")
ErrSkipResource skips a particular file from processing
var ( // Manager keeps track of all resources Manager = DefaultManager(osext.Executable) )
Functions ¶
func AddResource ¶
func AddResource(resource []byte)
AddResource adds resource to the default resource manager Note that the method may panic if the resource not exists
Types ¶
type Bundle ¶
type Bundle struct {
// Name of the resource
Name string
// Count returns the count of files in the bundle
Count int
// Body of the resource
Body []byte
}
Bundle represents a bundled resource
type Bundler ¶
type Bundler struct {
// Logger prints each step of compression
Logger io.Writer
// Compressor compresses the resources
Compressor Compressor
// FileSystem represents the underlying file system
FileSystem FileSystem
}
Bundler bundles the resources to the provided binary
func (*Bundler) Bundle ¶
func (e *Bundler) Bundle(ctx *BundlerContext) error
Bundle bundles the resources to the provided binary
type BundlerContext ¶
type BundlerContext struct {
// Name of the binary
Name string
// FileSystem represents the underlying file system
FileSystem FileSystem
}
BundlerContext the context of this bundler
type Compressor ¶
type Compressor interface {
// Compress compresses given source
Compress(ctx *CompressorContext) (*Bundle, error)
}
Compressor compresses given resource
type CompressorConfig ¶
type CompressorConfig struct {
// Logger prints each step of compression
Logger io.Writer
// Filename is the name of the compressed bundle
Filename string
// IgnorePatterns provides a list of all files that has to be ignored
IgnorePatterns []string
// Recurive enables embedding the resources recursively
Recurive bool
}
CompressorConfig controls how the code generation happens
type CompressorContext ¶
type CompressorContext struct {
// FileSystem file system that contain the files which will be compressed
FileSystem FileSystem
// Offset that should be applied
Offset int64
}
CompressorContext used for the compression
type Dir ¶
type Dir string
Dir implements FileSystem using the native file system restricted to a specific directory tree.
func (Dir) Dir ¶
func (d Dir) Dir(name string) (FileSystemManager, error)
Dir returns a sub-manager for given path
func (Dir) Open ¶
func (d Dir) Open(name string) (ReadOnlyFile, error)
Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *PathError.
type Embedder ¶
type Embedder struct {
// Logger prints each step of compression
Logger io.Writer
// Composer composes the resources
Composer Composer
// Compressor compresses the resources
Compressor Compressor
// FileSystem represents the underlying file system
FileSystem FileSystem
}
Embedder embeds the resources to the provided package
type ExecutableFunc ¶
ExecutableFunc returns the executable path
type File ¶
type File interface {
// A File is returned by a FileSystem's Open method and can be
ReadOnlyFile
// Writer is the interface that wraps the basic Write method.
io.Writer
// ReaderAt reads at specific position
io.ReaderAt
}
File is the bundle file
type FileSystem ¶
type FileSystem interface {
// A FileSystem implements access to a collection of named files.
http.FileSystem
// Walk walks the file tree rooted at root, calling walkFn for each file or
// directory in the tree, including root.
Walk(dir string, fn filepath.WalkFunc) error
// OpenFile is the generalized open call; most users will use Open
OpenFile(name string, flag int, perm os.FileMode) (File, error)
}
FileSystem provides primitives to work with the underlying file system
type FileSystemManager ¶
type FileSystemManager interface {
// FileSystem is the underlying file system
FileSystem
// Dir returns a sub-file-system
Dir(name string) (FileSystemManager, error)
// Add resource bundle to the manager
Add(resource *Resource) error
}
FileSystemManager is a file system that can create sub-file-systems
func DefaultManager ¶
func DefaultManager(executable ExecutableFunc) FileSystemManager
DefaultManager creates a FileSystemManager based on whether dev mode is enabled
func ManagerAt ¶
func ManagerAt(path string) FileSystemManager
ManagerAt returns manager at given path
type Generator ¶
type Generator struct {
// FileSystem represents the underlying file system
FileSystem FileSystem
// Config controls how the code generation happens
Config *GeneratorConfig
}
Generator generates an embedable resource
type GeneratorConfig ¶
type GeneratorConfig struct {
// Package determines the name of the package
Package string
// InlcudeDocs determines whether to include documentation
InlcudeDocs bool
}
GeneratorConfig controls how the code generation happens
type Node ¶
type Node struct {
// Name of the node
Name string
// IsDir returns true if the node is directory
IsDir bool
// Mutext keeps the node thread safe
Mutex *sync.RWMutex
// ModTime returns the last modified time
ModTime time.Time
// Content of the node
Content *[]byte
// Children of the node
Children []*Node
}
Node represents a node in resource tree
type Resource ¶
Resource represents a resource
func BinaryResource ¶
BinaryResource creates a binary resource
type ResourceFile ¶
ResourceFile represents a *bytes.Buffer that can be closed
func NewResourceFile ¶
func NewResourceFile(node *Node) *ResourceFile
NewResourceFile creates a new Buffer
type ResourceFileInfo ¶
type ResourceFileInfo struct {
Node *Node
}
ResourceFileInfo represents a hierarchy node in the resource manager
func (*ResourceFileInfo) IsDir ¶
func (n *ResourceFileInfo) IsDir() bool
IsDir returns true if the node is directory
func (*ResourceFileInfo) ModTime ¶
func (n *ResourceFileInfo) ModTime() time.Time
ModTime returns the modification time
func (*ResourceFileInfo) Mode ¶
func (n *ResourceFileInfo) Mode() os.FileMode
Mode returns the file mode bits
func (*ResourceFileInfo) Name ¶
func (n *ResourceFileInfo) Name() string
Name returns the base name of the file
func (*ResourceFileInfo) Size ¶
func (n *ResourceFileInfo) Size() int64
Size returns the length in bytes for regular files
func (*ResourceFileInfo) Sys ¶
func (n *ResourceFileInfo) Sys() interface{}
Sys returns the underlying data source
type ResourceManager ¶
type ResourceManager struct {
// NewReader creates a new ZIP Reader
NewReader func(io.ReaderAt, int64) (*zip.Reader, error)
// contains filtered or unexported fields
}
ResourceManager represents a virtual in memory file system
func NewResourceManager ¶
func NewResourceManager(cfg *ResourceManagerConfig) (*ResourceManager, error)
NewResourceManager creates a new manager
func (*ResourceManager) Add ¶
func (m *ResourceManager) Add(resource *Resource) error
Add adds resource to the manager
func (*ResourceManager) Dir ¶
func (m *ResourceManager) Dir(name string) (FileSystemManager, error)
Dir returns a sub-manager for given path
func (*ResourceManager) Open ¶
func (m *ResourceManager) Open(name string) (ReadOnlyFile, error)
Open opens an embedded resource for read
type ResourceManagerConfig ¶
type ResourceManagerConfig struct {
// Path to the archive
Path string
// FileSystem that stores the archive
FileSystem FileSystem
}
ResourceManagerConfig represents the configuration for Resource Manager
type ZipCompressor ¶
type ZipCompressor struct {
// Config controls how the compression is made
Config *CompressorConfig
}
ZipCompressor compresses content as GZip tarball
func (*ZipCompressor) Compress ¶
func (e *ZipCompressor) Compress(ctx *CompressorContext) (*Bundle, error)
Compress compresses given source in tar.gz
