remove gin use net/http

This commit is contained in:
2018-09-02 20:09:00 +08:00
parent ad9ca34089
commit 591586947d
4 changed files with 45 additions and 7 deletions

24
main.go
View File

@ -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, "<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"))
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)))
})
g.Run(":8080")
http.ListenAndServe(":8080", nil)
}