Skip to content
Pack static data in Go binaries
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.codecov.yaml
.travis.yml
README.markdown
go.mod
zpack.go
zpack_test.go

README.markdown

Build Status codecov GoDoc

zpack is yet another way to pack static data in Go binaries.

Why? Because I don't like relying on external binaries, and many other solutions do. zpack just writes data to the specified file as []byte().

Basic usage:

// +build go_run_only

package main

import (
    "fmt"
    "os"

    "zgo.at/zpack"
)

func main() {
    err := zpack.Pack(map[string]map[string]string{
        // Pack ./db/schema.sql in ./db/pack.go as the variable "Schema".
        "./db/pack.go": map[string]string{
            "Schema": "./db/schema.sql",
        },

        // Pack all files in the "./public" and "./tpl" directories.
        "./handlers/pack.go": map[string]string{
            "packPublic": "./public",
            "packTpl":    "./tpl",
        },
    })
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}

Then go generate ./... and presto!

You can’t perform that action at this time.