]> Sergey Matveev's repositories - goproxy.git/commitdiff
Initial revision master v0.1.0
authorSergey Matveev <stargrave@stargrave.org>
Mon, 26 Feb 2024 14:16:01 +0000 (17:16 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 26 Feb 2024 14:21:07 +0000 (17:21 +0300)
go.mod [new file with mode: 0644]
go.sum [new file with mode: 0644]
main.go [new file with mode: 0644]

diff --git a/go.mod b/go.mod
new file mode 100644 (file)
index 0000000..fa18cee
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,7 @@
+module go.stargrave.org/goproxy
+
+go 1.22.0
+
+require github.com/goproxy/goproxy v0.15.1
+
+require golang.org/x/mod v0.14.0 // indirect
diff --git a/go.sum b/go.sum
new file mode 100644 (file)
index 0000000..e5486f6
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,6 @@
+github.com/goproxy/goproxy v0.15.1 h1:8WIienqCHsudirStYC+c+zYeqIWLX1biZ1wT9ssb0D0=
+github.com/goproxy/goproxy v0.15.1/go.mod h1:OzNjaRaJSCtp35nVH6V6UvlIhrEOds1lDVgn6ZTEB/0=
+golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
+golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
+golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
+golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
diff --git a/main.go b/main.go
new file mode 100644 (file)
index 0000000..918ff96
--- /dev/null
+++ b/main.go
@@ -0,0 +1,36 @@
+package main
+
+import (
+       "flag"
+       "log"
+       "net/http"
+       "os"
+       "path"
+
+       "github.com/goproxy/goproxy"
+)
+
+type Logged struct{ goproxy http.Handler }
+
+func (l *Logged) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+       log.Print(r.URL)
+       l.goproxy.ServeHTTP(w, r)
+}
+
+func main() {
+       pth := flag.String("root", "/tmp/goproxy", "Path to storage")
+       bind := flag.String("bind", "[::1]:1234", "Address to listen on")
+       proxy := flag.String("proxy", "direct", "GOPROXY value")
+       sumdb := flag.String("sumdb", "off", "GOSUMDB value")
+       flag.Parse()
+       log.SetFlags(0)
+       log.Fatal(http.ListenAndServe(*bind, &Logged{&goproxy.Goproxy{
+               GoBinEnv: append(
+                       os.Environ(),
+                       "GOPATH="+path.Join(*pth, "gopath"),
+                       "GOPROXY="+*proxy,
+                       "GOSUMDB="+*sumdb,
+               ),
+               Cacher: goproxy.DirCacher(*pth),
+       }}))
+}