in python/rpdk/go/codegen.py [0:0]
def init(self, project):
LOG.debug("Init started")
self._prompt_for_go_path(project)
self._init_settings(project)
# .gitignore
path = project.root / ".gitignore"
LOG.debug("Writing .gitignore: %s", path)
contents = resource_stream(__name__, "data/go.gitignore").read()
project.safewrite(path, contents)
# project folder structure
src = project.root / "cmd" / "resource"
LOG.debug("Making source folder structure: %s", src)
src.mkdir(parents=True, exist_ok=True)
inter = project.root / "internal"
inter.mkdir(parents=True, exist_ok=True)
# Makefile
path = project.root / "Makefile"
LOG.debug("Writing Makefile: %s", path)
template = self.env.get_template("Makefile")
contents = template.render()
project.overwrite(path, contents)
# go.mod
path = project.root / "go.mod"
LOG.debug("Writing go.mod: %s", path)
template = self.env.get_template("go.mod.tple")
contents = template.render(
path=Path(
project.settings.get("import_path", project.settings.get("importpath"))
)
)
project.safewrite(path, contents)
# CloudFormation/SAM template for handler lambda
path = project.root / "template.yml"
LOG.debug("Writing SAM template: %s", path)
template = self.env.get_template("template.yml")
handler_params = {
"Handler": project.entrypoint,
"Runtime": project.runtime,
"CodeUri": self.CODE_URI,
}
test_handler_params = {
"Handler": project.entrypoint,
"Runtime": project.runtime,
"CodeUri": self.CODE_URI,
"Environment": "",
" Variables": "",
" MODE": "Test",
}
contents = template.render(
resource_type=project.type_name,
functions={
"TypeFunction": handler_params,
"TestEntrypoint": test_handler_params,
},
)
project.safewrite(path, contents)
LOG.debug("Writing handlers and tests")
self.init_handlers(project, src)
# README
path = project.root / "README.md"
LOG.debug("Writing README: %s", path)
template = self.env.get_template("README.md")
contents = template.render(
type_name=project.type_name,
schema_path=project.schema_path,
executable=EXECUTABLE,
files="model.go and main.go",
)
project.safewrite(path, contents)
LOG.debug("Init complete")