Your code is always yours, so we provide you with the coolest self-hosted Go module proxy building solution in the world. By using Goproxy, a minimalist project, you can easily add Go module proxy support to any existing web service, you know that Goproxy.cn is built on it.
Create a file named goproxy.go
package main
import (
"net/http"
"os"
"github.com/goproxy/goproxy"
)
func main() {
http.ListenAndServe("localhost:8080", &goproxy.Goproxy{
GoBinEnv: append(
os.Environ(),
"GOPROXY=https://goproxy.cn,direct", // Use Goproxy.cn as the upstream proxy
"GOPRIVATE=git.example.com", // Solve the problem of pulling private modules
),
ProxiedSUMDBs: []string{
"sum.golang.org https://goproxy.cn/sumdb/sum.golang.org", // Proxy the default checksum database
},
})
}
and run it
$ go run goproxy.go
then try it by setting GOPROXY to http://localhost:8080. In addition, we also recommend that you set GO111MODULE to on.
That's it, a fully functional Go module proxy is successfully built. In fact, you can use Goproxy with your favorite web frameworks, such as Gin and Echo, all you need to do is add one more route. For more advanced usage please check the documentation.