mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
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:
@@ -152,6 +152,8 @@ const static FlatCOption options[] = {
|
||||
{ "", "go-import", "IMPORT",
|
||||
"Generate the overriding import for flatbuffers in Golang (default is "
|
||||
"\"github.com/google/flatbuffers/go\")." },
|
||||
{ "", "go-module-name", "",
|
||||
"Prefix local import paths of generated go code with the module name" },
|
||||
{ "", "raw-binary", "",
|
||||
"Allow binaries without file_identifier to be read. This may crash flatc "
|
||||
"given a mismatched schema." },
|
||||
@@ -448,6 +450,9 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
} else if (arg == "--go-import") {
|
||||
if (++argi >= argc) Error("missing golang import" + arg, true);
|
||||
opts.go_import = argv[argi];
|
||||
} else if (arg == "--go-module-name") {
|
||||
if (++argi >= argc) Error("missing golang module name" + arg, true);
|
||||
opts.go_module_name = argv[argi];
|
||||
} else if (arg == "--defaults-json") {
|
||||
opts.output_default_scalars_in_json = true;
|
||||
} else if (arg == "--unknown-json") {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user