Documentation
¶
Overview ¶
Package vfsgen takes an http.FileSystem (likely at `go generate` time) and generates Go code that statically implements the provided http.FileSystem.
Features:
- Efficient generated code without unneccessary overhead.
- Uses gzip compression internally (selectively, only for files that compress well).
- Enables direct access to internal gzip compressed bytes via an optional interface.
- Outputs `gofmt`ed Go code.
Example ¶
This code will generate an assets_vfsdata.go file with `var assets http.FileSystem = ...` that statically implements the contents of "assets" directory.
vfsgen is great to use with go generate directives. This code can go in an assets_gen.go file, which can then be invoked via "//go:generate go run assets_gen.go". The input virtual filesystem can read directly from disk, or it can be more involved.
package main import ( "github.com/gozelle/vfs" "log" "net/http" ) func main() { var fs http.FileSystem = http.Dir("assets") err := vfs.Generate(fs, vfs.Options{}) if err != nil { log.Fatalln(err) } }
Output:
Index ¶
- Variables
- func Generate(input http.FileSystem, opt Options) error
- func Proxy(dir string) http.FileSystem
- func Walk(fs http.FileSystem, root string, fn WalkFunc) (err error)
- type CompressedFile
- type CompressedFileInfo
- func (f *CompressedFileInfo) GzipBytes() []byte
- func (f *CompressedFileInfo) IsDir() bool
- func (f *CompressedFileInfo) ModTime() time.Time
- func (f *CompressedFileInfo) Mode() os.FileMode
- func (f *CompressedFileInfo) Name() string
- func (f *CompressedFileInfo) Readdir(count int) ([]os.FileInfo, error)
- func (f *CompressedFileInfo) Size() int64
- func (f *CompressedFileInfo) Stat() (os.FileInfo, error)
- func (f *CompressedFileInfo) Sys() interface{}
- type Dir
- type DirInfo
- func (d *DirInfo) Close() error
- func (d *DirInfo) IsDir() bool
- func (d *DirInfo) ModTime() time.Time
- func (d *DirInfo) Mode() os.FileMode
- func (d *DirInfo) Name() string
- func (d *DirInfo) Read([]byte) (int, error)
- func (d *DirInfo) Size() int64
- func (d *DirInfo) Stat() (os.FileInfo, error)
- func (d *DirInfo) Sys() interface{}
- type FS
- type FileInfo
- type Options
- type WalkFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var SkipDir error = fsi.SkipDir
Functions ¶
func Generate ¶
func Generate(input http.FileSystem, opt Options) error
Generate Go code that statically implements input filesystem, write the output to a file specified in opt.
func Proxy ¶
func Proxy(dir string) http.FileSystem
Types ¶
type CompressedFile ¶
type CompressedFile struct { *CompressedFileInfo // contains filtered or unexported fields }
CompressedFile is an opened compressedFile instance.
func (*CompressedFile) Close ¶
func (f *CompressedFile) Close() error
type CompressedFileInfo ¶
type CompressedFileInfo struct {
// contains filtered or unexported fields
}
CompressedFileInfo is a static definition of a gzip compressed file.
func (*CompressedFileInfo) GzipBytes ¶
func (f *CompressedFileInfo) GzipBytes() []byte
func (*CompressedFileInfo) IsDir ¶
func (f *CompressedFileInfo) IsDir() bool
func (*CompressedFileInfo) ModTime ¶
func (f *CompressedFileInfo) ModTime() time.Time
func (*CompressedFileInfo) Mode ¶
func (f *CompressedFileInfo) Mode() os.FileMode
func (*CompressedFileInfo) Name ¶
func (f *CompressedFileInfo) Name() string
func (*CompressedFileInfo) Readdir ¶
func (f *CompressedFileInfo) Readdir(count int) ([]os.FileInfo, error)
func (*CompressedFileInfo) Size ¶
func (f *CompressedFileInfo) Size() int64
func (*CompressedFileInfo) Sys ¶
func (f *CompressedFileInfo) Sys() interface{}
type Dir ¶
type Dir struct { *DirInfo // contains filtered or unexported fields }
Dir is an opened dir instance.
type DirInfo ¶
type DirInfo struct {
// contains filtered or unexported fields
}
DirInfo is a static definition of a directory.
type Options ¶
type Options struct { // Filename of the generated Go code output (including extension). // If left empty, it defaults to "{{toLower .VariableName}}_vfsdata.go". Filename string // PackageName is the name of the package in the generated code. // If left empty, it defaults to "main". PackageName string // BuildTags are the optional build tags in the generated code. // The build tags syntax is specified by the go tool. BuildTags string // VariableName is the name of the http.FileSystem variable in the generated code. // If left empty, it defaults to "assets". VariableName string // VariableComment is the comment of the http.FileSystem variable in the generated code. // If left empty, it defaults to "{{.VariableName}} statically implements the virtual filesystem provided to vfsgen.". VariableComment string }
Options for vfsgen code generation.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
vfsgendev
vfsgendev is a convenience tool for using vfsgen in a common development configuration.
|
vfsgendev is a convenience tool for using vfsgen in a common development configuration. |
Package test contains tests for virtual filesystem implementation generated by vfsgen.
|
Package test contains tests for virtual filesystem implementation generated by vfsgen. |