vfsgen: github.com/shurcooL/vfsgen Index | Examples | Files | Directories

package vfsgen

import "github.com/shurcooL/vfsgen"

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.

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.

Code:

var fs http.FileSystem = http.Dir("assets")

err := vfsgen.Generate(fs, vfsgen.Options{})
if err != nil {
    log.Fatalln(err)
}

Index

Examples

Package Files

commentwriter.go doc.go generator.go options.go stringwriter.go

func Generate Uses

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.

type Options Uses

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.

Directories

PathSynopsis
cmd/vfsgendevvfsgendev is a convenience tool for using vfsgen in a common development configuration.
testPackage test contains tests for virtual filesystem implementation generated by vfsgen.

Package vfsgen imports 15 packages (graph) and is imported by 1 packages. Updated 2017-04-24. Refresh now. Tools for package owners.