nexus 代理 go

环境说明

服务 ip 端口 备注
nexus 192.168.80.129 (内网) 8081 内网地址无法访问外网
nginx

192.168.80.128 (内网)

192.168.174.126 (外网)

19000 nginx 代理到 https://goproxy.cn

创建 Blob Stores

创建 Repositories

nginx 配置

server {
    listen       19000;
    server_name  localhost;

    # 设置代理访问日志
    access_log  logs/proxy.access.log ;
    error_log  logs/proxy.error.log ;

    location /goproxy/ {
	    proxy_pass https://goproxy.cn/;
	    proxy_set_header Host "goproxy.cn";

    }

}

repo 测试

设置代理地址

export GOPROXY=http://192.168.80.128:8081/repository/go-repo/
export GO111MODULE=on
export GOSUMDB=off

测试代码

cat >> main.go << EOF
package main

import (
        "fmt"
        _ "net/http/pprof"

        _ "github.com/robfig/cron"
        _ "gorm.io/driver/mysql"
        _ "gorm.io/gorm"
        _ "gorm.io/gorm/logger"
        _ "github.com/gin-gonic/gin"
)

func main() {
        fmt.Println("hello")
}
EOF
# go mod init demo
go: creating new go.mod: module demo
go: to add module requirements and sums:
	go mod tidy

添加 module

# go mod tidy
go: finding module for package github.com/robfig/cron
go: finding module for package github.com/gin-gonic/gin
go: downloading github.com/gin-gonic/gin v1.9.1
go: downloading github.com/robfig/cron v1.2.0
go: finding module for package gorm.io/driver/mysql
go: downloading gorm.io/driver/mysql v1.5.6
go: finding module for package gorm.io/gorm
go: finding module for package gorm.io/gorm/logger
go: downloading gorm.io/gorm v1.25.8
go: found github.com/gin-gonic/gin in github.com/gin-gonic/gin v1.9.1
go: found github.com/robfig/cron in github.com/robfig/cron v1.2.0
go: found gorm.io/driver/mysql in gorm.io/driver/mysql v1.5.6
go: found gorm.io/gorm in gorm.io/gorm v1.25.8
go: found gorm.io/gorm/logger in gorm.io/gorm v1.25.8
go: downloading github.com/gin-contrib/sse v0.1.0
go: downloading github.com/mattn/go-isatty v0.0.19
go: downloading golang.org/x/net v0.10.0
go: downloading github.com/stretchr/testify v1.8.3
go: downloading google.golang.org/protobuf v1.30.0
go: downloading github.com/go-sql-driver/mysql v1.7.0
go: downloading github.com/jinzhu/now v1.1.5
go: downloading github.com/go-playground/validator/v10 v10.14.0
go: downloading github.com/pelletier/go-toml/v2 v2.0.8
go: downloading github.com/ugorji/go/codec v1.2.11
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/bytedance/sonic v1.9.1
go: downloading github.com/goccy/go-json v0.10.2
go: downloading github.com/json-iterator/go v1.1.12
go: downloading golang.org/x/sys v0.8.0
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading github.com/jinzhu/inflection v1.0.0
go: downloading github.com/gabriel-vasile/mimetype v1.4.2
go: downloading github.com/go-playground/universal-translator v0.18.1
go: downloading github.com/leodido/go-urn v1.2.4
go: downloading golang.org/x/crypto v0.9.0
go: downloading golang.org/x/text v0.9.0
go: downloading github.com/go-playground/locales v0.14.1
go: downloading github.com/modern-go/reflect2 v1.0.2
go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: downloading github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311
go: downloading golang.org/x/arch v0.3.0
go: downloading github.com/twitchyliquid64/golang-asm v0.15.1
go: downloading github.com/klauspost/cpuid/v2 v2.2.4
go: downloading github.com/go-playground/assert/v2 v2.2.0
go: downloading github.com/google/go-cmp v0.5.5
go: downloading gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
go: downloading golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543

build main.go

# go build main.go

执行程序

# ./main
hello

查看

posted @ 2024-03-26 13:12  小吉猫  阅读(98)  评论(0编辑  收藏  举报