From 6b2d9cacc4876fe1d5d107a37bdc4e099dd80bfe Mon Sep 17 00:00:00 2001 From: jack77213 Date: Sun, 16 Feb 2020 15:08:56 +0800 Subject: [PATCH] init --- go.mod | 3 +++ go.sum | 0 main.go | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6c58102 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module gitea.hijack.moe/huashui/extproxy + +go 1.13 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/main.go b/main.go new file mode 100644 index 0000000..0aba4a6 --- /dev/null +++ b/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "bytes" + "io/ioutil" + "net/http" + "os" +) + +func main() { + realServer := os.Getenv("REAL_SERVER") + listenAddress := os.Getenv("LISTEN_ADDR") + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.Method == "POST" { + b, _ := ioutil.ReadAll(http.NoBody) + go http.Post(realServer+r.URL.Path, r.Header.Get("Content-Type"), bytes.NewReader(b)) + } + }) + http.ListenAndServe(listenAddress, nil) +}