dongzi4030 2016-11-28 06:29
浏览 30
已采纳

“获取”如何了解与远程存储库一起使用的版本控制系统?

I am new to golang. I learned that go get serves as a package manager and contact remote repos with various version control systems.

So, given a package import path, how does go get decide which VCS to use? I always see below query string in the reqeust:

?go-get=1

So seems some protocol/convention here?

  • 写回答

1条回答 默认 最新

  • donglu5041 2016-11-28 06:43
    关注

    One of the nice things about Go is that everything is in, well, Go :-) Including almost all of the standard library and tools.

    In cmd/go/vcs.go we can see how this is done, and in cmd/go/alldocs.go it is documented.

    Specifically, look at repoRootForImportPath:

    // repoRootForImportPath analyzes importPath to determine the
    // version control system, and code repository to use.
    func repoRootForImportPath(importPath string, security securityMode) (*repoRoot, error) {
    

    What this does is:

    1. vcsPaths holds a static lists of "known hosts". For some (e.g. GitHub) this is easy and we can just set the VCS. For others (e.g. BitBucket) a callback function is used which examines the URL to see which repo can be used.

    2. If that fails, it tries to look at a "VCS extension" in the path, such as example.com/foo.git or example.com/foo.git/dir.

    3. And finally go get will look for a go-import meta tag, which looks like:

      <meta name="go-import" content="example.com/path git https://github.com/Example/repo.git">
      

      Also see parseMetaGoImports(). Vanity Imports with Hugo is a nice introduction on how to use this.

    There is no real "auto-detection" mechanism. So if you repo lives at https://example.com/stuff then go get example.com/stuff will not work. You need the extension or meta tags.

    The go-get=1 parameter is added so that it's easy for website builders to see that this is a request from go get, which may be useful in some cases.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格