I want to create a repo containing json files let us say mapping of countries to country ids, and import this repo in a golang package using git submodule for example called as transformer which reads the json for countries and creates a map and uses that for some operations.
sample structure
repoA:
-- country.json (mapping of country text to country id)
repoB: (golang package)
-- json (repoA added using git submodule)
-- transformer.go (logic to read json/country.json file and create lookup tables ).
repoC: (golang service)
-- main.go (uses repoB's transformer functionality).
When we import the created package (transformer or repoB), its dependency which is on repoA containing our country json file to read, is not imported in repoC and hence repoB package fails to read json.
tried to fetch submodules, tried to create build and run but json file was not being read.
expecting that the submodule dependency is present in the imported package.
One workaround is to add a generator in repoB to generate a go source file that holds the content of the json files. For example,
// jsondata.go
// Code generated by tool; DO NOT EDIT.
package jsondata
const file1 = `{"field":"value".....`
const file2 = `{"field":"value".....`
If the files are too large, you can zip them. Remember to put this file into a separate package so when this package is not imported, it won't affect the size of the final program.
This is how the go tool itself is designed to embed tzdata in a program. See this proposal for more information: time: add time/tzdata package and timetzdata tag to embed tzdata in program