GithubHelp home page GithubHelp logo

gopkg's Introduction

gopkg 本质上是一个反向代理, 只用于代理Golang的mod

原理

Golang的模块下载时使用go mod协议,实现了协议的代码仓库(如github、gitea)都在go命令发起"go-get=1"查询时都会返回一个html文本,格式如下:

<!doctype html>
<html>
	<head>
		<meta name="go-import" content="172.16.18.33/gopkg/demo git http://172.16.18.33/gopkg/demo.git">
		<meta name="go-source" content="172.16.18.33/gopkg/demo _ http://172.16.18.33/gopkg/demo/src/branch/dev{/dir} http://172.16.18.33/gopkg/demo/src/branch/dev{/dir}/{file}#L{line}">
	</head>
	<body>
		go get --insecure 172.16.18.33/gopkg/demo
	</body>
</html>

我们通过反向代理提供"go mod"服务时, 该地址需要同步被修改为代理前端, 即本命令行工具所解决的问题,经过本服务后格式转换为:

<!doctype html>
<html>
	<head>
		<meta name="go-import" content="code.local/gopkg/demo git http://code.local/gopkg/demo.git">
		<meta name="go-source" content="code.local/gopkg/demo _ http://code.local/gopkg/demo/src/branch/dev{/dir} http://code.local/gopkg/demo/src/branch/dev{/dir}/{file}#L{line}">
	</head>
	<body>
		go get --insecure code.local/gopkg/demo
	</body>
</html>

Usage

go run . -backend https://172.16.18.33 -frontend http://code.local -addr :8081 -debug

说明

nginx 代理

location / {
		proxy_pass http://localhost:8081/;
		proxy_set_header Host $http_host;
	}

本机hosts

127.0.0.1 code.local

gopkg's People

Contributors

qingtao avatar

Watchers

 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.