Giter Site home page Giter Site logo

rookiefiend / goproxy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from goproxy/goproxy

0.0 0.0 0.0 512 KB

A minimalist Go module proxy handler.

Home Page: https://pkg.go.dev/github.com/goproxy/goproxy

License: MIT License

Go 99.40% Dockerfile 0.60%

goproxy's Introduction

Goproxy

Test codecov Go Report Card PkgGoDev

A minimalist Go module proxy handler.

Goproxy has fully implemented the GOPROXY protocol. The goal of this project is to find the most dead simple way to provide a minimalist handler that can act as a full-featured Go module proxy for those who want to build their own proxies.

Features

Installation

  • To use this project programmatically, go get it:
go get github.com/goproxy/goproxy
  • To use this project from the command line, download the pre-built binaries from here or build it from source:
go install github.com/goproxy/goproxy/cmd/goproxy@latest
  • To use this project with Docker, pull the pre-built images from here:
docker pull ghcr.io/goproxy/goproxy

Quick Start

Write code

Create a file named goproxy.go:

package main

import (
	"net/http"

	"github.com/goproxy/goproxy"
)

func main() {
	http.ListenAndServe("localhost:8080", &goproxy.Goproxy{})
}

Then run it with a GOMODCACHE that differs from go env GOMODCACHE:

GOMODCACHE=/tmp/goproxy-gomodcache go run goproxy.go

Finally, set GOPROXY to try it out:

go env -w GOPROXY=http://localhost:8080,direct

For more details, refer to the documentation.

Run from command line

Refer to the Installation section to download or build the binary.

Then run it with a GOMODCACHE that differs from go env GOMODCACHE:

GOMODCACHE=/tmp/goproxy-gomodcache goproxy server --address localhost:8080

Finally, set GOPROXY to try it out:

go env -w GOPROXY=http://localhost:8080,direct

For more details, check its usage:

goproxy --help
Run with Docker

Refer to the Installation section to pull the image.

Then run it:

docker run -p 8080:8080 ghcr.io/goproxy/goproxy server --address :8080

Finally, set GOPROXY to try it out:

go env -w GOPROXY=http://localhost:8080,direct

For more details, check its usage:

docker run ghcr.io/goproxy/goproxy --help

Modify

此工程改造了原始goproxy,增加了通过文件上传依赖功能,为其添加了/* POST接口,可通过任意HTTP路径,采用POST方法上传依赖文件,具体代码位于goproxy.go文件中的serveSync方法之中,可查询此方法进行修改。

若需重新编译并制作镜像,可在有网环境下执行docker build -t goproxy:v0.16-upload .命令制作镜像,然后进行使用。

Usage

手动上传依赖

  1. 有网构建工程,下载依赖

    在有网环境中,构建简单的 go module 项目,通过 import 导入所需依赖,然后通过 go mod tidy 下载依赖到本机的 go env GOMODCACHE 目录之下

  2. 打包依赖

    通过以下代码打包依赖

    tar -zcf download.tar.gz -C $(go env OMODCACHE)/cache/download .
  3. 拷贝依赖包到无网环境

  4. 上传依赖包

    1. 通过界面上传

      访问 goproxy 程序的 / 路径,通过界面选择文件进行上传即可

    2. 通过 curl 上传

      示例代码如下

       filePath=/home/test/download.tar.gz # 设置要上传文件路径
       proxyServer=http://localhost:8080/ # 代理地址
       curl --request POST --url ${proxyServer} --header 'content-type: multipart/	form-data' -F "file=@${filePath};type=file -b --mime-type ${filePath}"

Community

If you have any questions or ideas about this project, feel free to discuss them here.

Contributing

If you would like to contribute to this project, please submit issues here or pull requests here.

License

This project is licensed under the MIT License.

goproxy's People

Contributors

aofei avatar vrischmann avatar zhangyunhao116 avatar dependabot[bot] avatar sgtcodfish avatar wizardishungry avatar lwalen 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.