#include json file in build

10 messages · Page 1 of 1 (latest)

idle vine
#

I'm trying to create an app that has a default config written in json. It parses this JSON into database entries. Works well. However, i've noticed that when I build the project, it doesn't include these files. Is there any way to include these JSON files in the build?

desert magnet
#

yes look up embed

idle vine
desert magnet
idle vine
#

thx

idle vine
# desert magnet https://pkg.go.dev/embed

I'm trying to implement this, and i've gotten this

        //go:embed config/default_ranks.json
        var defaultRanksJson []byte
        err := InitializeRanksFromJSON(defaultRanksJson)

but VSCode is complaining

go:embed directives must precede a "var" declaration

Am I misunderstanding something here?

desert magnet
#

it has to be a global outside of function

idle vine
#

this fixed it!

desert magnet
#

yw!