Back to godoc.org
zgo.at/zpack

Package zpack

v1.0.1
Latest Go to latest
Published: Feb 7, 2020 | License: MIT | Module: zgo.at/zpack

Index

Package Files

func Dir

func Dir(fp io.Writer, varname, dir string, ignore ...string) error

Dir recursively writes all files in a directory as variables.

The ignore patterns are matched by strings.HasSuffix().

func File

func File(fp io.Writer, varname, path string) error

File writes a single file as a variable.

func Format

func Format(path string) error

Format the given file with gofmt.

func Header(fp io.Writer, pkg string) error

Header writes a file header, which is a code generation comment and package declaration.

func Pack

func Pack(data map[string]map[string]string, ignore ...string) error

Pack data to a Go file.

The data is a map where the key is the filename to store the packed data, and the contents a variable -> contents mapping.

Example:

err := zpack.Pack(map[string]map[string]string{
    "./db/pack.go": map[string]string{
        "Schema": "./db/schema.sql",
    },
    "./handlers/pack.go": map[string]string{
        "packPublic": "./public",
        "packTpl":    "./tpl",
    },
})
if err != nil {
    fmt.Fprintln(os.Stderr, err)
    os.Exit(1)
}

The ignore patterns are matched by strings.HasSuffix().

func Varname

func Varname(s string) string

Varname replaces any sequence of invalid identifier characters with an _.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier