GithubHelp home page GithubHelp logo

artyom / assetfs Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 8 KB

Command to generate http.FileSystem implementation compiling assets into Go binary

License: MIT License

Go 99.06% HTML 0.94%
go filesystem static-website

assetfs's Introduction

Command assetfs generates http.FileSystem implementation compiling assets inside go binary as byte slices. Generated file exposes function AssetDir() which usage is similar to http.Dir() usage.

assetfs can generate 2 files: one for production usage, where assets should be compiled inside binary, and one for development usage, where AssetDir() is aliases to http.Dir() and files are served from disk. As both files exposes function with the same name, they're differentiated with build tags.

Usage: assetfs [flags] assetsDir ...
  -dev string
	path to write development stub
  -devtag string
	build tag to assign to development stub (default "dev")
  -name string
	package name
  -out string
	path to write generated content
  -tag string
	build tag to use for main generated file

This program is mainly intended to be used with go generate as follows:

Consider your repository has static subdirectory which is normally exposed as http.Dir("static"). Create file static.go with the following content:

package mypackage
//go:generate assetfs static

Once you run go generate, it will produce two extra files: static_assetfs.go and static_assetfs-dev.go. Both expose AssetDir() function, the latter has this function aliased to http.Dir() and has dev build tag set, so it can be used during development when you expect to see changes in static files as you refresh page. Next thing to do would be to replace usage of http.Dir("static") with AssetDir("static") in your code.

assetfs main intention is to include small static assets inside compiled Go binary, so that resulting program has less file dependencies. As all included files are stored as byte slices, they affect both binary size and runtime memory consumption, so you should avoid including large files. Currently the only artificial limit built in is for a single file size (10 MiB).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.