zgok

Golang library to create a single binary with asset files.

  • 所有者: srtkkou/zgok
  • 平台:
  • 许可证: Apache License 2.0
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Zgok

GoDoc Build Status

Zgok is a simple utility to embed any static file
into the binary executable file for Go.

日本語: README.jp.md

Features

  • It can create a single binary file containing all static files. Easy to deploy!
  • No dependency. Available on Windows, Linux, Mac and ARM.

Installation

Use the following to install the library and command line program:

go get -u github.com/srtkkou/zgok/...

Usage

Use the following command to build the zgok executable file.

$GOPATH/bin/zgok build -e exePath -z zipPath1 -z zipPath2 -o outPath

If you want to read the embedded file in the code, you can do like the
following.

package main

import (
	"fmt"
	"github.com/srtkkou/zgok"
	"io/ioutil"
	"os"
)

func main() {
	var content []byte
	path := "test.txt"
	zfs, _ := zgok.RestoreFileSystem(os.Args[0])
	if zfs != nil {
		// For release.
		content, _ = zfs.ReadFile(path)
	} else {
		// For development.
		content, _ = ioutil.ReadFile(path)
	}
	fmt.Println(string(content))
}

If you want to serve zgok embedded files as static files in the
web application, you can do like the following.
Note: Assuming that static assets are stored in [./web/public/*].

  1. This is the minimal example to use the zgok in web application.
package main

import (
	"net/http"
	"github.com/srtkkou/zgok"
	"os"
)

func main() {
	zfs, err := zgok.RestoreFileSystem(os.Args[0])
	if err != nil {
		panic(err)
	}
	assetServer := zfs.FileServer("web/public")
	http.Handle("/assets/", http.StripPrefix("/assets/", assetServer))
	http.ListenAndServe(":8080", nil)
}
  1. Build the zgok executable file.

    go build -o web web.go
    $GOPATH/bin/zgok build -e web -z web/public -o web_all

  2. Access the URL like [http://localhost:8080/assets/css/sample.css] on browser.

Description

The file format of Linux executable file (ELF) and that of the Windows (PE)
starts with a header section containing the sizes of each segments in the file.
In other words, the executable file knows its REAL size by themselves.
So you can add some extra data at the end of the executable file, and still
use it normally.

The format of the zgok executable file looks like the following., Header section, --------------, Section 1, Section 2, ..., Section n, Zip data, Zgok signature, Zgok will unzip the files in the zip data section and add the content of them
in a map accessible by their path.

License

Apache License Version 2.0. See the LICENSE file for details.

主要指标

概览
名称与所有者srtkkou/zgok
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证Apache License 2.0
所有者活动
创建于2015-11-04 08:51:39
推送于2021-05-12 05:58:49
最后一次提交
发布数2
最新版本名称v0.0.1 (发布于 )
第一版名称v0.0.0 (发布于 2019-09-17 11:55:26)
用户参与
星数68
关注者数1
派生数5
提交数54
已启用问题?
问题数2
打开的问题数0
拉请求数0
打开的拉请求数0
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?