Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. vfsgen

vfsgen

MITGo

Generates Go code that statically implements an http.FileSystem, enabling efficient embedding of assets into Go binaries.

GitHubGitHub
983 stars81 forks0 contributors

What is vfsgen?

vfsgen is a Go library that generates static Go code implementations of http.FileSystem interfaces, allowing assets to be embedded directly into Go binaries. It solves the problem of managing external asset files in deployments by compiling them into the executable. The tool is typically used at `go generate` time to create efficient, compressed representations of directories and files.

Target Audience

Go developers who need to embed static assets (like web resources, templates, or configuration files) into their binaries for simplified distribution and deployment. It's particularly useful for projects building web servers, CLI tools with embedded resources, or any Go application requiring portable asset management.

Value Proposition

Developers choose vfsgen for its simplicity centered on the standard http.FileSystem interface, efficient generated code with smart gzip compression, and seamless integration with Go's build system and `go generate`. It avoids unnecessary overhead by merging functionality that often requires multiple packages into a single, focused tool.

Overview

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

Use Cases

Best For

  • Embedding web assets (HTML, CSS, JS) into Go web server binaries
  • Creating self-contained CLI tools with embedded templates or configuration
  • Simplifying deployment by eliminating external asset dependencies
  • Optimizing asset delivery with built-in gzip compression
  • Using Go build tags to switch between development and production asset modes
  • Generating static http.FileSystem implementations for use with net/http FileServer

Not Ideal For

  • Projects using languages other than Go or requiring cross-platform asset embedding without Go toolchain
  • Applications where assets change dynamically at runtime and recompilation is not feasible
  • Teams preferring to rely solely on Go's standard library, specifically the embed package introduced in Go 1.16

Pros & Cons

Pros

Efficient Code Generation

Produces optimized Go code automatically formatted by gofmt, minimizing runtime overhead and ensuring clean output, as highlighted in the features section.

Smart Compression

Uses gzip compression selectively only for files that benefit, reducing binary size without unnecessary bloat, which is explicitly mentioned in the README.

Build Tag Integration

Seamlessly works with Go build tags to enable development modes with live filesystem access and production builds with embedded assets, as demonstrated in the usage examples.

Standard Interface Focus

Centers on the http.FileSystem interface, allowing flexibility through middleware and wrappers without vfsgen-specific knowledge, promoting orthogonality as per the philosophy.

Cons

Setup Complexity

Requires configuring go generate directives and potentially separate helper files like assets_generate.go, adding initial boilerplate compared to simpler alternatives.

External Dependency

Relies on a third-party library and binary (vfsgendev), introducing maintenance risk and potential compatibility issues with future Go versions or ecosystems.

Static Asset Limitations

Once embedded, assets cannot be modified at runtime without recompiling the binary, making it unsuitable for scenarios requiring dynamic updates or hot reloading.

Frequently Asked Questions

Quick Stats

Stars983
Forks81
Contributors0
Open Issues25
Last commit2 years ago
CreatedSince 2015

Tags

#build-tools#static-files#binary-embedding#go-generate#go#compression#code-generation

Built With

G
Go

Included in

Go169.1k
Auto-fetched 1 day ago

Related Projects

debmedebme

embed.FS wrapper providing additional functionality

Stars35
Forks7
Last commit5 years ago
rebedrebed

Recreates directory and files from embedded filesystem using Go 1.16 embed.FS type.

Stars30
Forks2
Last commit4 years ago
embedembed

Package embed provides access to files embedded in the running Go program

Stars0
Forks0
Last commit
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub