I'm trying to insert a file as a variable in a go file using go generate
but it fails with bad quoted string
, the issue is that I can run this in a shell without issue:
//go:generate echo "var baseConfigProduction = \`" && cat base-production.json && echo "\`"
What am I missing here?
Go generate only works by calling one command. If you want to call several, you either put them into a BASH script, or do something like this:
//go:generate echo var baseConfigProduction = `
//go:generate cat base-production.json
//go:generate echo `
But AFAIK, the order of evaluation for several go:generate
commands is undefined, so you can't really count on that, so I would recommend sticking to BASH scripts.
EDIT: Another possibility:
//go:generate sh -c "echo var baseConfigProduction = \\`$DOLLAR(cat base-production.json)\\`"