Embedding static resources in Go binaries

Tsvetan Dimitrov

Agenda

  • Why?

  • Introducing Statik

  • Integration

    • Local Development

    • Dockerfile integration

    • CircleCI integration

Why? / 1

  • No moving parts (everything is self contained)

  • No reference of file paths when trying to read or write

  • Adheres to Go philosophy of a self contained deliverable

Why? / 2

  • Can serve static content via a web server directly from the binary, e.g. JS, HTML, CSS, images, etc.

  • Go Proposal

Introducing Statik

Statik

  • Tool allowing embedding of a directory of static content in your binary

  • Could be served later from a http.FileSystem or just reference it as pure Go code

How to do it?

1. Generate a Go package with serialized content

2. Add a blank import of the generated package to, e.g. main.go

3. Load content by file name to read or serve

DEMO

Integration

DEMO

References

Questions?

Embedding static resources in Go binaries

By Tsvetan Dimitrov

Embedding static resources in Go binaries

Introduction on ways to embed static resources in Go binaries and why that is beneficial

  • 171