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

Module

zgo.at/zpack

README

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!

Source: zgo.at/zpack@v1.0.1/README.markdown