in python/rpdk/go/codegen.py [0:0]
def generate(self, project):
LOG.debug("Generate started")
root = project.root / "cmd"
# project folder structure
src = root / "resource"
format_paths = []
LOG.debug("Writing Types")
models = resolve_models(project.schema)
template = self.env.get_template("types.go.tple")
path = src / "{}.go".format("model")
contents = template.render(models=models)
project.overwrite(path, contents)
format_paths.append(path)
path = root / "main.go"
LOG.debug("Writing project: %s", path)
template = self.env.get_template("main.go.tple")
importpath = Path(
project.settings.get("import_path", project.settings.get("importpath"))
)
contents = template.render(path=(importpath / "cmd" / "resource").as_posix())
project.overwrite(path, contents)
format_paths.append(path)
# makebuild
path = project.root / "makebuild"
LOG.debug("Writing makebuild: %s", path)
template = self.env.get_template("makebuild")
contents = template.render()
project.overwrite(path, contents)
# named files must all be in one directory
for path in format_paths:
try:
subprocess_run(
["go", "fmt", path], cwd=root, check=True, stdout=PIPE, stderr=PIPE
)
except (FileNotFoundError, CalledProcessError) as e:
raise DownstreamError("go fmt failed") from e
# Update settings as needed
need_to_write = False
for key, new in DEFAULT_SETTINGS.items():
old = project.settings.get(key)
if project.settings.get(key) != new:
LOG.debug(f"{key} version change from {old} to {new}")
project.settings[key] = new
need_to_write = True
if key == "pluginVersion":
# Display any upgrade messages
print(*check_version(old), sep="\n")
if need_to_write:
project.write_settings()