Documentation
¶
Overview ¶
Package zgok provides a simple library to create a single binary with asset files in Go (Golang).
Example:
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)
}
Index ¶
Constants ¶
View Source
const ( APP_BYTE_SIZE = 8 // Byte size of the signature app field. SIGNATURE_BYTE_SIZE = 64 // Byte size of the signature. )
View Source
const ( APP = "zgok" // Application name. MAJOR = 0 // Major version. MINOR = 0 // Minor version. REV = 1 // Revision. )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Builder ¶
type Builder interface {
SetExePath(exePath string) error
AddZipPath(zipPath string) error
SetOutPath(outPath string)
Build() error
}
Builder interface.
type File ¶
type File interface {
SetPath(path string) // Set file path.
Path() string // Get file path.
SetFileInfo(fileInfo os.FileInfo) // Set file info.
FileInfo() os.FileInfo // Get file info.
SetBytes(content []byte) // Set content bytes.
Bytes() []byte // Get content bytes.
SetNewReader() // Set a new reader.
Close() error // Implements [net/http.File.Close]
Read(p []byte) (int, error) // Implements [net/http.File.Read]
Readdir(count int) ([]os.FileInfo, error) // Implements [net/http.File.Readdir]
Seek(offset int64, whence int) (int64, error) // Implements [net/http.File.Seek]
Stat() (os.FileInfo, error) // Implements [net/http.File.Stat]
}
File interface.
type FileSystem ¶
type FileSystem interface {
AddFile(file File)
GetFile(path string) (File, error)
ReadFile(path string) ([]byte, error)
ReadFileString(path string) (string, error)
Paths() []string
SubFileSystem(rootPath string) (FileSystem, error)
Signature() Signature
SetSignature(signature Signature)
String() string
Open(name string) (http.File, error) // Implements [net/http.FileSystem.Open]
FileServer(basePath string) http.Handler // Get a static file server.
}
File system interface. Implements net/http.FileSystem
func RestoreFileSystem ¶
func RestoreFileSystem(path string) (FileSystem, error)
Restore file system.
type Signature ¶
type Signature interface {
ExeSize() int64
SetExeSize(exeSize int64)
ZipSize() int64
SetZipSize(zipSize int64)
TotalSize() int64
String() string
Dump() ([]byte, error)
}
Signature interface.
func RestoreSignature ¶
Restore signature from bytes.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.