ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - go-playground/statics: :file_folder: Embeds static resources into go files for single binary compilation + works with http.FileSystem + symlinks
:file_folder: Embeds static resources into go files for single binary compilation + works with http.FileSystem + symlinks - go-playground/statics
Visit Site

GitHub - go-playground/statics: :file_folder: Embeds static resources into go files for single binary compilation + works with http.FileSystem + symlinks

GitHub - go-playground/statics: :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.

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory