Dra-M Dra-M
首页
技术
冥思
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

莫小龙

保持理智,相信未来。
首页
技术
冥思
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Java基础

  • Spring

  • 微服务

  • Elasticsearch

  • Golang

    • GitLab私服+Go Modules踩坑经验(SSH自定义端口)
      • 【代码片段】我使用的Gin中间处理器(自定义异常处理、日志打印、traceId、跨域配置)
      • 【Java转Go】如何理解Go中的值类型、引用类型、nil
      • 【Java转Go】如何理解面向对象,怎么把Golang用成面向对象的样子
    • 实用工具

    • Bash

    • DevOps系列

    • 技术
    • Golang
    莫小龙
    2022-08-31
    目录

    GitLab私服+Go Modules踩坑经验(SSH自定义端口)

    环境是GitLab私服,私有仓库,仅允许SSH拉取,自定义端口。

    遇到过的错误有:

    go: unrecognized import path "git.dev.dra-m.com/common/test-private-module": parse http://git.dev.dra-m.com/common/test-private-module?go-get=1: no go-import meta tags (meta tag git.dev.dra-m.com:9999/common/test-private-module did not match import path git.dev.dra-m.com/common/test-private-module)
    
    
    
    status 128:
            fatal: unable to connect to git.dev.dra-m.com:
            git.dev.dra-m.com[0: 192.168.98.18]: errno=Unknown error
    		
    
    
    go: downloading git.dev.dra-m.com/common/test-private-module.git v0.0.0-20220831074151-6d5aa689f730
    go: git.dev.dra-m.com/common/test-private-module.git@v0.0.0-20220831074151-6d5aa689f730: parsing go.mod:
            module declares its path as: git.dev.dra-m.com/common/test-private-module
                    but was required as: git.dev.dra-m.com/common/test-private-module.git
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15

    # 配置Go Proxy跳过私服域名

    go env -w GOPRIVATE=git.dev.dra-m.com
    
    1

    # 在.gitconfig中替换url

    当使用go get 拉取包名时 go get,会使用git clone https://包名。

    例如 go get dra-m.com/test,等价于 git clone https://dra-m.com/test。

    因为我的私服仅允许ssh,且自定义端口,所以如下配置.gitconfig:

    [url "ssh://git@git.dev.dra-m.com:30386/"]
    insteadOf = https://git.dev.dra-m.com.com/
    
    1
    2

    这意味着实际发出的命令将变成 git clone ssh://git@git.dev.dra-m.com:30386/test。

    但gitlab中通过ssh拉取必须以.git结尾,所以要求我们的module名也以.git结尾:

    # go.mod文件module以.git结尾

    module git.dev.dra-m.com/common/test-private-module.git
    
    1

    导入时模块名一致:

    import (
    	"git.dev.dra-m.com/common/test-private-module.git/common"
    )
    
    1
    2
    3

    # DockerFile 构建时包含私服包

    RUN go env -w GOPRIVATE=git.dev.dra-m.com
    RUN git config --global  url."ssh://git@git.dev.dra-m.com:30386/".insteadof https://git.dev.dra-m.com/
    COPY ./build/id_rsa.pub /root/.ssh/id_rsa.pub
    ADD ./build/id_rsa  /root/.ssh/id_rsa
    RUN chmod -R 700 ~/.ssh/*
    RUN ssh -o "StrictHostKeyChecking no" git@git.dev.dra-m.com -p30386
    
    RUN go mod tidy
    ...
    
    1
    2
    3
    4
    5
    6
    7
    8
    9

    #Golang#GitLab
    上次更新: 3/6/2023
    Spring Data ElasticSearch 快速起步
    【代码片段】我使用的Gin中间处理器(自定义异常处理、日志打印、traceId、跨域配置)

    ← Spring Data ElasticSearch 快速起步 【代码片段】我使用的Gin中间处理器(自定义异常处理、日志打印、traceId、跨域配置)→

    最近更新
    01
    【代码片段】我使用的Gin中间处理器(自定义异常处理、日志打印、traceId、跨域配置)
    12-03
    02
    【Java转Go】如何理解Go中的值类型、引用类型、nil
    12-03
    03
    【Java转Go】如何理解面向对象,怎么把Golang用成面向对象的样子
    12-02
    更多文章>
    Theme by Vdoing | Copyright © 2019-2023 Dra-M | 冀ICP备2021002204号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式