1

I am developing a web server and I want to have all embedded on the same file.

I want to develop index.html, main.css, and scripts.js on separated files, but I want them to be read on compile time and embedded into the executable.

Is this posible with Go?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Alejo Dev
  • 2,290
  • 4
  • 29
  • 45
  • 3
    You likely want [`go generate`](https://blog.golang.org/generate), which is a pre-compilation step but allows for what you're describing. – Adrian Dec 17 '20 at 19:54

1 Answers1

1

Use the //go:embed directive and the embed package in Go 1.16

thwd
  • 27
  • 1
  • 2
    If using an unreleased version of go (1.16 release expected Feb 2021) does not appeal then consider one of the existing solutions mentioned in the [embed design draft](https://go.googlesource.com/proposal/+/master/design/draft-embed.md) (along with go generate). – Brits Dec 17 '20 at 20:23
  • Note that Go 1.16 release candidate 1 is out today. – John Dec 17 '20 at 21:58