简体   繁体   English

go.mod 中的模块名称别名

[英]Module name alias in go.mod

Is there a way to use a shorter name representation/mapping in modules?有没有办法在模块中使用更短的名称表示/映射?

I have a project, with an url naming:我有一个项目,命名为 url:

module github.com/<org>/<project>    
go 1.14

Would be nice to be able to do:能够做到这一点会很高兴:

import "<short_name>/<project>/package_folder"

From a go.mod , something like:go.mod ,类似于:

module github.com/<org>/<project> => short_name
go 1.14

Nope, there is no way to define an alias in the go.mod file.不,没有办法在go.mod文件中定义别名。

It was proposed but rejected for reasons explained here .它被提议但由于此处解释的原因而被拒绝。

I've run into this recently with a poorly named internal repo.我最近遇到了一个命名不佳的内部回购协议。 Go doesn't do this, but with some git magic you can get close. Go 不这样做,但是通过一些 git 魔法,您可以接近。

In your ~/.gitconfig add something like this: [url "ssh://git@github.com//"] insteadOf = https://github.com/ <go_mod_org>/<go_mod_repo>在你的 ~/.gitconfig 添加如下内容: [url "ssh://git@github.com//"] insteadOf = https://github.com/ <go_mod_org>/<go_mod_repo>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM