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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?