Documentation ¶
Overview ¶
go-assets is a simple embedding asset generator and consumer library for go. The main use of the library is to generate and embed small in-memory file systems ready to be integrated in webservers or other services which have a small amount of assets used at runtime. This is great for being able to do single binary deployments with assets.
The Generator type can be used to generate a go file containing an in-memory file tree from files and directories on disk. The file data can be optionally compressed using gzip to reduce file size. Afterwards, the generated file can be included into your application and the assets can be directly accessed without having to load them from disk. The generated assets variable is of type FileSystem and implements the os.FileInfo and http.FileSystem interfaces so that they can be directly used with http.FileHandler.
Index ¶
- type File
- func (f *File) Close() error
- func (f *File) IsDir() bool
- func (f *File) ModTime() time.Time
- func (f *File) Mode() os.FileMode
- func (f *File) Name() string
- func (f *File) Read(data []byte) (int, error)
- func (f *File) Readdir(count int) ([]os.FileInfo, error)
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) Size() int64
- func (f *File) Stat() (os.FileInfo, error)
- func (f *File) Sys() interface{}
- type FileSystem
- type Generator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct { // The full asset file path Path string // The asset file mode FileMode os.FileMode // The asset modification time Mtime time.Time // The asset data. Note that this data might be in gzip compressed form. Data []byte // contains filtered or unexported fields }
An asset file.
type FileSystem ¶
type FileSystem struct { // A map of directory paths to the files in those directories. Dirs map[string][]string // A map of file/directory paths to assets.File types. Files map[string]*File // Override loading assets from local path. Useful for development. LocalPath string }
An in-memory asset file system. The file system implements the http.FileSystem interface.
func NewFileSystem ¶
type Generator ¶
type Generator struct { // The package name to generate assets in, PackageName string // The variable name containing the asset filesystem (defaults to Assets), VariableName string // Strip the specified prefix from all paths, StripPrefix string // contains filtered or unexported fields }
An asset generator. The generator can be used to generate an asset go file with all the assets that were added to the generator embedded into it. The generated assets are made available by the specified go variable VariableName which is of type assets.FileSystem.
Example ¶
g := Generator{} if err := g.Add("."); err != nil { panic(err) } // This will write a go file to standard out. The generated go file // will reside in the g.PackageName package and will contain a // single variable g.VariableName of type assets.FileSystem containing // the whole file system. g.Write(os.Stdout)
Output: