nexus 3.17.0 作为golang 的包管理工具

nexus 3.17.0 作为golang 的包管理工具

nexus 3.17.0 新版本对于go 包管理的支持是基于go mod 的,同时咱们也须要一个athens server
而后在nexus 中配置proxy 类型的repogit

参考配置

  • 来自官方的配置图

watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=

 

  • 说明
    就和上边说的同样,咱们须要一个athens server,nexus 对于go mod 的支持就是经过配置proxy到athens server
    同时为了使用须要配置GOPROXY 环境变量

环境搭建

  • docker-compose 文件
version: "3"
services:
nexus:
image: sonatype/nexus3:3.17.0
ports:
- "80:8081"
volumes:
- "./nexus-data:/nexus-data"
athens:
image: gomods/athens:latest
ports:
- "3000:3000"
  • 配置go proxy

watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=

 

golang 代码使用proxy

  • 配置host 文件
    由于localhost 有问题,因此简单配置了一个127.0.0.1 dalongrong.com
 
127.0.0.1  dalongrong.com
  • 简单go mod 项目
go mod init github.com/rongfengliang/nexus-mod
go: creating new go.mod: module github.com/rongfengliang/nexus-mod
  • 一个简单的http server 代码
main.go:
package main
import (
"fmt"
"net/http"
"github.com/urfave/negroni"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Welcome to the home page!")
})
n := negroni.Classic() // Includes some default middlewares
n.UseHandler(mux)
http.ListenAndServe(":8000", n)
}
  • 配置GOPROXY
export GOPROXY=http://dalongrong.com/repository/golang/
  • 添加缺乏的依赖
go mod tidy
  • 构建
go build
  • 运行
./nexus-mod

效果github

├── go.mod
├── go.sum
├── main.go
└── nexus-mod
  • nexus 系统proxy 的信息

watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=

 

说明

以上是一个简单的学习试用,同时也支持group 类型的,仍是很不错的golang

参考资料

https://help.sonatype.com/repomanager3/release-notes/2019-release-notes#id-2019ReleaseNotes-RepositoryManager3.17.0 
https://help.sonatype.com/repomanager3/formats/go-repositories 
https://github.com/rongfengliang/nexus-golang-packagedocker

相关文章
相关标签/搜索