英文:
How do I properly use recursive replace in golang's go.mod?
问题
我想要一个项目结构,看起来像这样:
src/github.com/myname/myproject/
- tl:
- constructor
- something.go
- go.mod:
module github.com/myname/myproject/tl/constructor
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
require github.com/myname/myproject/tl/types/account v0.0.0
require github.com/myname/myproject/tl/types/auth v0.0.0
require github.com/myname/myproject/tl/types/bots v0.0.0
replace github.com/myname/myproject v0.0.0 => ./../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./../types
replace github.com/myname/myproject/tl/types/account v0.0.0 => ./../types/account
replace github.com/myname/myproject/tl/types/auth v0.0.0 => ./../types/auth
replace github.com/myname/myproject/tl/types/channels v0.0.0 => ./../types/channels
- crcs
- something.go
- go.mod:
module github.com/myname/myproject/tl/crcs
- functions
- account
- something.go
- go.mod:
module github.com/myname/myproject/tl/functions/account
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./../../types
- auth
- something.go
- go.mod:
module github.com/myname/myproject/tl/functions/auth
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./../../types
- bots
- something.go
- go.mod:
module github.com/myname/myproject/tl/functions/bots
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./../../types
- something.go
- go.mod:
module github.com/myname/myproject/tl/functions
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../crcs
replace github.com/myname/myproject v0.0.0 => ./../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./../types
- types
- account
- something.go
- go.mod:
module github.com/myname/myproject/tl/types/account
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./..
- auth
- something.go
- go.mod:
module github.com/myname/myproject/tl/types/auth
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./..
- channels
- something.go
- go.mod:
module github.com/myname/myproject/tl/types/channels
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./..
- something.go
- go.mod:
module github.com/myname/myproject/tl/types
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../crcs
replace github.com/myname/myproject v0.0.0 => ./../..
- something.go
- go.mod:
module github.com/myname/myproject
[一些外部依赖]
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/l/types v0.0.0 => ./tl/types
这个结构无法工作。我使用JetBrains的IDE,在所有(子)模块上执行go list命令,并告诉我以下错误:
go: github.com/myname/myproject/tl/types@v0.0.0 requires
github.com/myname/myproject/tl/crcs@v0.0.0: reading github.com/myname/myproject/tl/crcs/go.mod at revision tl/crcs/v0.0.0: unknown revision tl/crcs/v0.0.0
我不明白为什么会发生这种情况,看起来它尝试从存储库获取模块,尽管一切都在本地替换了。
我接受建议,除了更改项目结构。我需要能够在将来使用类似account.SomeType
的东西,所以将所有内容放在一个文件中将很痛苦。
背景:我正在为Telegram构建MTPROTO库,其中包含TL模式,每个“请求”/“类”都在自己的命名空间中(例如“account”,“channels”)(或在全局命名空间中,对我来说是functions
和types
)(因为有超过1900个这样的函数/类,每个都有自己的构造函数和参数,将所有内容放在一个模块中将很难使用)
TL文件夹中的文件是从TL模式自动生成的GO代码。
英文:
I want a project structure, looking like this:
src/github.com/myname/myproject/
- tl:
- constructor
- someghing.go
- go.mod:
module github.com/myname/myproject/tl/constructor
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
require github.com/myname/myproject/tl/types/account v0.0.0
require github.com/myname/myproject/tl/types/auth v0.0.0
require github.com/myname/myproject/tl/types/bots v0.0.0
replace github.com/myname/myproject v0.0.0 => ./../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./../types
replace github.com/myname/myproject/tl/types/account v0.0.0 => ./../types/account
replace github.com/myname/myproject/tl/types/auth v0.0.0 => ./../types/auth
replace github.com/myname/myproject/tl/types/channels v0.0.0 => ./../types/channels
- crcs
- someghing.go
- go.mod:
module github.com/myname/myproject/tl/crcs
- functions
- account
- someghing.go
- go.mod:
module github.com/myname/myproject/tl/functions/account
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./../../types
- auth
- someghing.go
- go.mod:
module github.com/myname/myproject/tl/functions/auth
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./../../types
- bots
- someghing.go
- go.mod:
module github.com/myname/myproject/tl/functions/bots
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./../../types
- someghing.go
- go.mod:
module github.com/myname/myproject/tl/functions
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../crcs
replace github.com/myname/myproject v0.0.0 => ./../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./../types
- types
- account
- something.go
- go.mod:
module github.com/myname/myproject/tl/types/account
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./..
- auth
- something.go
- go.mod:
module github.com/myname/myproject/tl/types/auth
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./..
- channels
- something.go
- go.mod:
module github.com/myname/myproject/tl/types/channels
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../../crcs
replace github.com/myname/myproject v0.0.0 => ./../../..
replace github.com/myname/myproject/tl/types v0.0.0 => ./..
- someghing.go
- go.mod:
module github.com/myname/myproject/tl/types
require github.com/myname/myproject/tl/crcs v0.0.0
require github.com/myname/myproject v0.0.0
replace github.com/myname/myproject/tl/crcs v0.0.0 => ./../crcs
replace github.com/myname/myproject v0.0.0 => ./../..
- something.go
- go.mod:
module github.com/myname/myproject
[some external dependencies]
require github.com/myname/myproject/tl/types v0.0.0
replace github.com/myname/myproject/l/types v0.0.0 => ./tl/types
This does not work. I use JetBrains' IDE, which executes go list on all the (sub)modules, and tells me the following error:
go: github.com/myname/myproject/tl/types@v0.0.0 requires
github.com/myname/myproject/tl/crcs@v0.0.0: reading github.com/myname/myproject/tl/crcs/go.mod at revision tl/crcs/v0.0.0: unknown revision tl/crcs/v0.0.0
I don't understand why is it happening, it looks like it tries fetching module from repo, even though everything is replaced locally.
I am open to suggestions, except changing project structure. I need to be able to use something like account.SomeType
in future, so placing everything in one file would be painful.
Context: I'm building MTPROTO library for telegram, which has TL schema, where each "request"/"class" is in its own namespace (e.g. "account", "channels") (or in global namespace, for me it's functions
and types
accordingly) (Because there is over 1900 of those functions/classes, each having its own constructor and parametrs, putting everything in one module would be hard to use)
the files in TL folder are auto-generated GO code from TL schema.
答案1
得分: 0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论