Code Monkey home page Code Monkey logo

goproxy's Introduction

GOPROXY

CircleCI Go Report Card GoDoc

A global proxy for go modules. see: https://goproxy.io

Update

本项目用来构建即刻内部的 goproxy 代理,封装了如下细节:

  • 通过 proxy 加速访问 github 私有 repo。
  • 使用多个 upstream backend 代理公共 repo,默认情况下优先从 https://goproxy.cn 拉取依赖,支持重试,如果重试仍然不过,会继续使用 https://mirrors.aliyun.com/goproxy/ 代理再次重试。
  • 使用 https://goproxy.cn 代理 golang 官方 sum.golang.org 的校验。
  • 增加一层 cache。

用户在使用时只需要配置如下环境变量即可:

# GONOSUMDB 让 go cli 对于私有 repo 不校验 sumdb,必须在go get 前配置该变量
# 必须将 GOPRIVATE 变量置为空(若已经为空不用处理),否则 go cli 将不会走 GOPROXY 拉取 GOPRIVATE 中定义的路径
GOPRIVATE="" GONOSUMDB="github.com/iftechio" GOPROXY=http://goproxy.infra.svc.cluster.local:8081 go get -v github.com/iftechio/jike-sdk/go

Requirements

It invokes the local go command to answer requests.
The default cacheDir is GOPATH, you can set it up by yourself according to the situation.

Build

git clone https://github.com/goproxyio/goproxy.git
cd goproxy
make

Started

Proxy mode

./bin/goproxy -listen=0.0.0.0:80 -cacheDir=/tmp/test

If you run `go get -v pkg` in the proxy machine, should set a new GOPATH which is different from the old GOPATH, or mayebe deadlock.
See the file test/get_test.sh.

Router mode

Use the -proxy flag switch to "Router mode", which implements route filter to routing private module or public module .

                                         direct
                      +----------------------------------> private repo
                      |
                 match|pattern
                      |
                  +---+---+           +----------+
go get  +-------> |goproxy| +-------> |goproxy.io| +---> golang.org/x/net
                  +-------+           +----------+
                 router mode           proxy mode

In Router mode, use the -exclude flag set pattern , direct to the repo which match the module path, pattern are matched to the full path specified, not only to the host component.

./bin/goproxy -listen=0.0.0.0:80 -cacheDir=/tmp/test -proxy https://goproxy.io -exclude "*.corp.example.com,rsc.io/private"

Use docker image

docker run -d -p80:8081 goproxy/goproxy

Use the -v flag to persisting the proxy module data (change cacheDir to your own dir):

docker run -d -p80:8081 -v cacheDir:/go goproxy/goproxy

Docker Compose

docker-compose up

Appendix

  1. set export GOPROXY=http://localhost to enable your goproxy.
  2. set export GOPROXY=direct to disable it.

goproxy's People

Contributors

oiooj avatar hxzhao527 avatar ianwoolf avatar fsm-xyz avatar stanxing avatar prologic avatar rainbowmango avatar fancy-rabbit avatar jsign avatar nafisfaysal avatar rmfish avatar codeskyblue avatar pingtest avatar na4ma4 avatar imneov avatar edwardpro avatar bastjan avatar senmumu avatar superryanguo avatar mmelnyk avatar schemacs avatar mr-tron avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.