remove gin use net/http
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -24,3 +24,4 @@ _testmain.go
 | 
				
			|||||||
*.test
 | 
					*.test
 | 
				
			||||||
*.prof
 | 
					*.prof
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/vendor
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,6 @@
 | 
				
			|||||||
FROM golang:alpine AS build
 | 
					FROM golang:alpine AS build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WORKDIR /go/src/github.com/yumc.pw/cloud
 | 
					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 .
 | 
					ADD main.go .
 | 
				
			||||||
RUN go build
 | 
					RUN go build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								main.go
									
									
									
									
									
								
							@@ -1,11 +1,25 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "github.com/gin-gonic/gin"
 | 
					import (
 | 
				
			||||||
 | 
						"flag"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	g := gin.Default()
 | 
						s := flag.String("s", "yumc.pw", "Source Server Host(Default: yumc.pw)")
 | 
				
			||||||
	g.GET("/:n/:p", func(c *gin.Context) {
 | 
						t := flag.String("t", "https://git.yumc.pw", "Target Server Host(Default: https://git.yumc.pw)")
 | 
				
			||||||
		c.String(200, "<meta name=\"go-import\" content=\"yumc.pw/%s/%s git https://git.yumc.pw/%s/%s\">", c.Param("n"), c.Param("p"), c.Param("n"), c.Param("p"))
 | 
						p := flag.String("p", "git", "Target Server Type(Default: git)")
 | 
				
			||||||
	})
 | 
						flag.Parse()
 | 
				
			||||||
	g.Run(":8080")
 | 
						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("<meta name=\"go-import\" content=\"%s%s %s %s%s\">",
 | 
				
			||||||
 | 
									*s, path, *p, *t, path)))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						http.ListenAndServe(":8080", nil)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										25
									
								
								test/test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								test/test.go
									
									
									
									
									
										Normal file
									
								
							@@ -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("<meta name=\"go-import\" content=\"%s%s %s %s%s\">",
 | 
				
			||||||
 | 
									*s, path, *p, *t, path)))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						http.ListenAndServe(":8080", nil)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user