Example #1
0
// 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.
func Example() {
	var fs http.FileSystem = http.Dir("assets")

	err := vfsgen.Generate(fs, vfsgen.Options{})
	if err != nil {
		log.Fatalln(err)
	}
}
Example #2
0
func main() {
	err := vfsgen.Generate(assets, vfsgen.Options{
		BuildTags: "!dev",
	})
	if err != nil {
		log.Fatalln(err)
	}
}
Example #3
0
func main() {
	err := vfsgen.Generate(tmpl.Data, vfsgen.Options{
		PackageName:  "tmpl",
		BuildTags:    "!dev",
		VariableName: "Data",
	})
	if err != nil {
		log.Fatalln(err)
	}
}
Example #4
0
func main() {
	var fs http.FileSystem = httpfs.New(mapfs.New(map[string]string{
		"sample-file.txt":                "This file compresses well. Blaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah!",
		"not-worth-compressing-file.txt": "Its normal contents are here.",
		"folderA/file1.txt":              "Stuff in /folderA/file1.txt.",
		"folderA/file2.txt":              "Stuff in /folderA/file2.txt.",
		"folderB/folderC/file3.txt":      "Stuff in /folderB/folderC/file3.txt.",
		// TODO: Empty folder somehow?
		//"folder-empty/":                  "",
	}))

	err := vfsgen.Generate(fs, vfsgen.Options{
		Filename:    "test_vfsdata_test.go",
		PackageName: "test_test",
	})
	if err != nil {
		log.Fatalln(err)
	}
}