Add --go-module-name flag to support generating Go module compatible code (#7651)

* Add --go-module-name flag to support generating code for go modules

* Rename echo example folder

* Grammar

* Update readme for go-echo example

* Update readme for go-echo example

* Re-enable go modules after test is done
This commit is contained in:
Michael Le
2022-11-22 14:28:01 -08:00
committed by GitHub
parent 60975d6f7e
commit e000458bb1
13 changed files with 419 additions and 2 deletions

View File

@@ -1532,7 +1532,12 @@ class GoGenerator : public BaseGenerator {
// Create the full path for the imported namespace (format: A/B/C).
std::string NamespaceImportPath(const Namespace *ns) const {
return namer_.Directories(*ns, SkipDir::OutputPathAndTrailingPathSeparator);
std::string path =
namer_.Directories(*ns, SkipDir::OutputPathAndTrailingPathSeparator);
if (!parser_.opts.go_module_name.empty()) {
path = parser_.opts.go_module_name + "/" + path;
}
return path;
}
// Ensure that a type is prefixed with its go package import name if it is