:file_folder: Embeds static resources into go files for single binary compilation + works with http.FileSystem + symlinks

Package statics

Project status Build Status Go Report Card GoDoc License

Package statics embeds static files into your go applications. It provides helper methods and objects to retrieve embeded files and serve via http.

It has the following unique features:

  • Follows Symlinks! uses the symlinked file/directory name and path but the contents and other fileinfo of the original file.
  • Embeds static generation command for using go:generate in each static file for easy generation in production mode.
  • Handles multiple static go files, even inside of the same package.
  • Handles development (aka local files) vs production (aka static files) across packages.

Installation

	go get -u github.com/go-playground/statics

Then import the statics package into your own code.

import "github.com/go-playground/statics"

Usage and documentation

Please see https://godoc.org/github.com/go-playground/statics/static for detailed usage docs.

NOTE: when specifying path or directory name in code always use "/", even for you windows users, the package handles any conversion to you local filesystem paths; Except for the AbsPkgPath variable in the config.

run statics -h to see the options/arguments

Examples:

Embedding in Source Control

statics -i=assets -o=assets.go -pkg=main -group=Assets -ignore=\\.gitignore -init=true

Output:

//go:generate statics -i=assets -o=assets.go -pkg=main -group=Assets -ignore=\.gitignore

package main

import "github.com/go-playground/statics/static"

// newStaticAssets initializes a new *static.Files instance for use
func newStaticAssets(config *static.Config) (*static.Files, error) {

	return static.New(config, &static.DirFile{})
}

when using arg init=true statics package generates a minimal configuration with no files embeded; you can then add it to source control, ignore the file locally using git update-index --assume-unchanged [filename(s)] and then when ready for generation just run go generate from the project root and the files will get embedded ready for compilation.

Be sure to check out this packages best buddy https://github.com/go-playground/generate to help get everything generated and ready for compilation.

Example Usage

// generated via command: 
// statics -i=assets -o=assets.go -pkg=main -group=Assets -ignore=//.gitignore

gopath := getGopath() // retrieved from environment variable
pkgPath := "/src/github.com/username/project"

// get absolute directory path of the -i arguments parent directory + any prefix 
// removed, used when UseStaticFiles=false this is so even when referencing this 
// package from another project and your PWD is not for this package anymore the 
// file paths will still work.
pkg := goapth + pkgPath

config := &static.Config{
	UseStaticFiles: true,
	AbsPkgPath:     pkg,
}

// NOTE: Assets in the function name below is the group in the generation command
assets, err := newStaticAssets(config)
if err != nil {
	log.Println(err)
}

// when using http
http.Handle("/assets", http.FileServer(assets.FS()))

// other methods for direct access
assets.GetHTTPFile
assets.ReadFile
assets.ReadDir
assets.ReadFiles

Package Versioning

I'm jumping on the vendoring bandwagon, you should vendor this package as I will not be creating different version with gopkg.in like allot of my other libraries.

Why? because my time is spread pretty thin maintaining all of the libraries I have + LIFE, it is so freeing not to worry about it and will help me keep pouring out bigger and better things for you the community.

License

Distributed under MIT License, please see license file in code for more details.

Owner
Go Playgound
multiple packages, libraries and programs to further the advancement of Go!
Go Playgound
Similar Resources

Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

kubectl-slice: split Kubernetes YAMLs into files kubectl-slice is a neat tool that allows you to split a single multi-YAML Kubernetes manifest into mu

Jan 3, 2023

DEPRECATED. Embeds mruby (mini Ruby) VM into Go.

GoMRuby Package gomruby embeds mruby (mini Ruby) VM into Go. Documentation. Installation It's slightly more than just go get: go get -d github.com/Ale

May 17, 2022

🌳 📂 The utility displays a tree of directories and files(symlinks in future).

dirTree The utility displays a tree of directories and files. usage: dirTree [-f] How it works with directory, where I wrote this project for example

Aug 12, 2021

Run your MapReduce workloads as a single binary on a single machine with multiple CPUs and high memory. Pricing of a lot of small machines vs heavy machines is the same on most cloud providers.

gomap Run your MapReduce workloads as a single binary on a single machine with multiple CPUs and high memory. Pricing of a lot of small machines vs he

Sep 16, 2022

Unfancy resources embedding for Go with out of box http.FileSystem support.

Resources Unfancy resources embedding with Go. No blings. No runtime dependency. Idiomatic Library First design. Dude, Why? Yes, there is quite a lot

Oct 19, 2022

Package filippo.io/intermediates embeds a bundle of known unexpired, unrevoked intermediate certificates chaining to roots in the Mozilla Root Program

filippo.io/intermediates Package intermediates embeds a list of known unexpired, unrevoked intermediate certificates chaining to roots with Websites t

Nov 7, 2022

Sim - Command-line tool to manage program symlinks in $XDG_BIN_HOME.

Sim Sim is a command-line tool that manages program symlinks in $XDG_BIN_HOME. Get started Run make install. Make sure your PATH contains $XDG_BIN_HOM

Jan 3, 2022

Dotsync - Dotfiles manager without symlinks

dotsync dotfiles manager without symlinks Getting Started SYNOPSIS $ dotsync rep

Feb 12, 2022

🦉 Docuowl generates a static single-page documentation from Markdown files

🦉 Docuowl generates a static single-page documentation from Markdown files

🦉 Docuowl generates a static single-page documentation from Markdown files

Jan 2, 2023

A cross platform single binary tool to work with draw io files

SNIPO SNIPIO is a cross platform single binary tool to work with draw io files With snipio you can do the following operations: list all layers in a d

Jan 7, 2023

Simple, secure and modern Go HTTP server to serve static sites, single-page applications or a file with ease

srv srv is a simple, secure and modern HTTP server, written in Go, to serve static sites, single-page applications or a file with ease. You can use it

Sep 7, 2022

This static analysis tool works to ensure your program's data flow does not spill beyond its banks.

Go Flow Levee This static analysis tool works to ensure your program's data flow does not spill beyond its banks. An input program's data flow is expl

Dec 1, 2022

Build Go Toolchains /w native libs for cross-compilation

gonative Cross compiled Go binaries are not suitable for production applications because code in the standard library relies on Cgo for DNS resolution

Dec 20, 2022

Gos: Armed Golang 💪 ( solutions for go module, goproxy, cross compilation, etc.)

Gos: Armed Golang 💪 ( solutions for go module, goproxy, cross compilation, etc.)

The current gos is still an alpha version, welcome more heroes to comment and improve it 🍓 , you can add more commands to it, or modify something to make it perform better.

Sep 15, 2022

hotbuild - a cross platform hot compilation tool for golang

hotbuild - a cross platform hot compilation tool for golang

hotbuild A cross platform hot compilation tool By monitoring the modification of the project directory file, the recompilation and running are automat

Dec 12, 2022

Http-recorder - Application for record http response as static files

Http-recorder - Application for record http response as static files

http-recorder This is a application for record http response as static files. Th

Mar 21, 2022

Merge multiple pprof profile files into a single file

pprof-merge Merges multiple pprof profile files into one. Installation $ go get github.com/rakyll/pprof-merge Usage $ pprof-merge profile1.data profi

Dec 15, 2022

The simple and easy way to embed static files into Go binaries.

NOTICE: Please consider migrating your projects to github.com/markbates/pkger. It has an idiomatic API, minimal dependencies, a stronger test suite (t

Dec 25, 2022

erchive is a go program that compresses and encrypts files and entire directories into .zep files (encrypted zip files).

erchive/zep erchive is a go program that compresses and encrypts files and entire directories into .zep files (encrypted zip files). it compresses usi

May 16, 2022
The simple and easy way to embed static files into Go binaries.

NOTICE: Please consider migrating your projects to github.com/markbates/pkger. It has an idiomatic API, minimal dependencies, a stronger test suite (t

Dec 25, 2022
Takes an input http.FileSystem (likely at go generate time) and generates Go code that statically implements it.

vfsgen Package vfsgen takes an http.FileSystem (likely at go generate time) and generates Go code that statically implements the provided http.FileSys

Dec 18, 2022
Using brotli compression to embed static files in Go.
Using brotli compression to embed static files in Go.

?? Broccoli go get -u aletheia.icu/broccoli Broccoli uses brotli compression to embed a virtual file system of static files inside Go executables. A f

Nov 25, 2022
Generates go code to embed resource files into your library or executable

Deprecating Notice go is now going to officially support embedding files. The go command will support //go:embed tags. Go Embed Generates go code to e

Jun 2, 2021
Embed files into a Go executable

statik statik allows you to embed a directory of static files into your Go binary to be later served from an http.FileSystem. Is this a crazy idea? No

Dec 29, 2022
A tool to be used with 'go generate' to embed external template files into Go code.

templify A tool to be used with 'go generate' to embed external template files into Go code. Scenario An often used scenario in developing go applicat

Sep 27, 2022
go.rice is a Go package that makes working with resources such as html,js,css,images,templates, etc very easy.

go.rice go.rice is a Go package that makes working with resources such as html,js,css,images and templates easy. During development go.rice will load

Dec 29, 2022
a better customizable tool to embed files in go; also update embedded files remotely without restarting the server

fileb0x What is fileb0x? A better customizable tool to embed files in go. It is an alternative to go-bindata that have better features and organized c

Dec 27, 2022
Nightly binary builds of Emacs for macOS as a self-contained Emacs.app, with native-compilation.

Emacs Builds Nightly binary builds of Emacs for macOS as a self-contained Emacs.app, with native-compilation. Features Self-contained Emacs.app applic

Dec 25, 2022
Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

Dec 29, 2022