nexus 3.17.0 新版本對於go 包管理的支持是基於go mod 的,同時我們也需要一個athens server
然后在nexus 中配置proxy 類型的repo
參考配置
- 來自官方的配置圖

- 說明
就和上邊說的一樣,我們需要一個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

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
效果
├── go.mod
├── go.sum
├── main.go
└── nexus-mod
- nexus 系統proxy 的信息

說明
以上是一個簡單的學習試用,同時也支持group 類型的,還是很不錯的
參考資料
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-package
