This is an example that's more elaborate and closer to real world use cases corresponding to a web application.
We have a ./static
folder which contains all multiple types of files,
CSS styles, JavaScript files, an SVG document and some other plain text or binary resources.
For the stylesheets, JavaScript files and the SVG document we want to minify them before using
them as a assets in our binary.
Because //go:embed
doesn't support adding functionality into the embed pipeline, we are forced
to create our own generator, which creates a fs.FS
compatible object, that we map our assets group
on top of.
To use this example:
go generate main.go
minify: checking package: main.go:12:32: undeclared name: mount
minify: proceeding anyway...
go run main.go
2022/08/05 14:11:06 [GET] /main.js 3.006738ms
Load one file:
curl http://localhost:6699/main.js
console.log("Hello!!!");console.error("Minification!!");