From 591586947d9e3c79200870e5b48705a75cc6c071 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Sun, 2 Sep 2018 20:09:00 +0800 Subject: [PATCH] remove gin use net/http --- .gitignore | 1 + Dockerfile | 2 -- main.go | 24 +++++++++++++++++++----- test/test.go | 25 +++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 test/test.go diff --git a/.gitignore b/.gitignore index d3beee5..085b491 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ _testmain.go *.test *.prof +/vendor diff --git a/Dockerfile b/Dockerfile index cc5e5d4..92a7620 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ FROM golang:alpine AS build WORKDIR /go/src/github.com/yumc.pw/cloud -RUN apk add --no-cache git -RUN go get github.com/gin-gonic/gin ADD main.go . RUN go build diff --git a/main.go b/main.go index 4939d46..4c49f0e 100644 --- a/main.go +++ b/main.go @@ -1,11 +1,25 @@ package main -import "github.com/gin-gonic/gin" +import ( + "flag" + "fmt" + "net/http" + "strings" +) func main() { - g := gin.Default() - g.GET("/:n/:p", func(c *gin.Context) { - c.String(200, "", c.Param("n"), c.Param("p"), c.Param("n"), c.Param("p")) + s := flag.String("s", "yumc.pw", "Source Server Host(Default: yumc.pw)") + t := flag.String("t", "https://git.yumc.pw", "Target Server Host(Default: https://git.yumc.pw)") + p := flag.String("p", "git", "Target Server Type(Default: git)") + flag.Parse() + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + path := r.RequestURI + if strings.Contains(path, "?") { + path = strings.Split(path, "?")[0] + } + w.Write([]byte( + fmt.Sprintf("", + *s, path, *p, *t, path))) }) - g.Run(":8080") + http.ListenAndServe(":8080", nil) } diff --git a/test/test.go b/test/test.go new file mode 100644 index 0000000..4c49f0e --- /dev/null +++ b/test/test.go @@ -0,0 +1,25 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "strings" +) + +func main() { + s := flag.String("s", "yumc.pw", "Source Server Host(Default: yumc.pw)") + t := flag.String("t", "https://git.yumc.pw", "Target Server Host(Default: https://git.yumc.pw)") + p := flag.String("p", "git", "Target Server Type(Default: git)") + flag.Parse() + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + path := r.RequestURI + if strings.Contains(path, "?") { + path = strings.Split(path, "?")[0] + } + w.Write([]byte( + fmt.Sprintf("", + *s, path, *p, *t, path))) + }) + http.ListenAndServe(":8080", nil) +}