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

莫小龙

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

  • Golang

    • GitLab私服+Go Modules踩坑经验(SSH自定义端口)
      • 【代码片段】我使用的Gin中间处理器(自定义异常处理、日志打印、traceId、跨域配置)
      • 【Java转Go】如何理解Go中的值类型、引用类型、nil
      • 【Java转Go】如何理解面向对象,怎么把Golang用成面向对象的样子
      • Golang 调度器 GMP 原理与调度全分析
      • Go中GMP有哪些状态?
      • 一文搞懂go gc垃圾回收原理
      • Go什么时候发生阻塞?阻塞时,调度器会怎么做?
      • Go netpoller 原生网络模型之源码全面揭秘
      • Goroutine 泄露 - 被遗忘的发送者
      • go map 设计与实现
      • go slice 设计与实现
      • 小白也能看懂的context包详解:从入门到精通
      • go interface 设计与实现
      • 深入理解 go chan
      • go chan 设计与实现
      • 深入理解 go Mutex
      • 深入理解 go sync.Map - 基本原理
      • go sync.Map 设计与实现
      • 深入理解 go sync.Once
      • 深入理解 go reflect - 反射基本原理
      • 深入理解 go reflect - 要不要传指针
    • 编程思想

    • 微服务

    • 中间件

    • Python

    • 运维

    • 技术
    • 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/[email protected]: 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://[email protected]:30386/"]
    insteadOf = https://git.dev.dra-m.com.com/
    
    1
    2

    这意味着实际发出的命令将变成 git clone ssh://[email protected]: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://[email protected]: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" [email protected] -p30386
    
    RUN go mod tidy
    ...
    
    1
    2
    3
    4
    5
    6
    7
    8
    9

    #Golang#GitLab
    上次更新: 10/23/2024
    JAVA快速导出Excel
    【代码片段】我使用的Gin中间处理器(自定义异常处理、日志打印、traceId、跨域配置)

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

    最近更新
    01
    mosquito配置ws协议
    10-23
    02
    Pip包的离线下载和安装
    10-23
    03
    stable diffusion 相关收藏
    02-24
    更多文章>
    Theme by Vdoing | Copyright © 2019-2024 Dra-M
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式