英文:
keep directory structure when generating files
问题
我有以下 thrift 接口:
./thrift/a/a1.thrift
./thrift/a/a2.thrift
./thrift/b/b1.thrift
./thrift/b/b2.thrift
其中 a1.thrift 包含了 a2、b1 和 b2(使用 include "thrift/a/a2.thrift")
我使用 thrift -r --gen go:package_prefix=work -I . --out . thrift/a/a1.thrift 为它们生成了 Go 文件
生成的文件如下:
./a1/constants.go
./a1/ttypes.go
./a2/...
./b1/...
./b2/...
我该如何告诉 thrift 输出到以下目录?
./a/a1/...
./a/a2/...
./b/b1/...
./b/b2/...
请注意,我可以手动移动这些文件,但首先我有很多文件,其次在 Go 中包必须与目录匹配,所以我需要编辑这些文件。例如,生成的 a1 的 Go 文件将把 a2 导入为 work/a2 而不是 work/a/a2。
英文:
I have those thrift interfaces:
./thrift/a/a1.thrift
./thrift/a/a2.thrift
./thrift/b/b1.thrift
./thrift/b/b2.thrift
where a1.thrift includes a2, b1, b2 (with include "thrift/a/a2.thrift")
I generate the Go files for all those with thrift -r --gen go:package_prefix=work -I . --out . thrift/a/a1.thrift 
It outputs:
./a1/constants.go
./a1/ttypes.go
./a2/...
./b1/...
./b2/...
How can I tell thrift to output in?
./a/a1/...
./a/a2/...
./b/b1/...
./b/b2/...
Note that I can move those files by hand but first I have many and second in Go the package has to match the directories, so I would need to edit those files. As an example the generated Go file for a1 will import a2 as work/a2 and not work/a/a2)
答案1
得分: 1
使用命名空间。在每个IDL文件的顶部添加类似以下的行:
 namespace go a.a1   // 根据需要修改,但每个IDL文件只能有一个命名空间
运行以下命令:
thrift -r -gen go a1.thrift
会在以下路径下生成文件:
 gen-go/a/a1/*
英文:
Use namespaces. Add a line similar to the following on top of each IDL file:
 namespace go a.a1   // whatever you need, but exactly one per IDL file
Running
thrift -r -gen go a1.thrift
creates files under
 gen-go/a/a1/*
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论