How to Use go

embed with Build Tags for Different Environments

Use build tags on separate source files to include different embedded assets for different environments.

You cannot use go:embed with build tags to select different files for different environments because go:embed directives are processed at compile time and must be valid for the specific build configuration. Instead, use build tags on the file containing the go:embed directive itself to include different files in different builds.

//go:build linux

package main

import "embed"

//go:embed config-linux.json
var ConfigData embed.FS
//go:build windows

package main

import "embed"

//go:embed config-windows.json
var ConfigData embed.FS