diff --git a/README.md b/README.md index 672e836..1291b6c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# gh-proxy-go +# ghproxy 这是 [gh-proxy](https://github.com/hunshcn/gh-proxy) 的 Go 语言版本。 @@ -16,4 +16,7 @@ --- -如有问题或改进建议,欢迎提交 issue 或 PR! +如有问题或改进建议,欢迎提交 [issue] 或 PR! + + +[issue]: https://github.com/oopsunix/ghproxy/issues \ No newline at end of file diff --git a/config.json b/config.json index 1759066..1f75a4c 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,5 @@ { + "domain": "gh.llkk.cc", "whiteList": [ ], "blackList": [ diff --git a/main.go b/main.go index 21d8aa7..c64d3a4 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" "sync" + "text/template" "time" "github.com/gin-gonic/gin" @@ -39,6 +40,7 @@ var ( type Config struct { WhiteList []string `json:"whiteList"` BlackList []string `json:"blackList"` + Domain string `json:"domain"` } func main() { @@ -68,11 +70,31 @@ func main() { } }() - router.StaticFile("/", "./public/index.html") + tmpl, err := template.ParseFiles("./public/index.html") + if err != nil { + fmt.Printf("Error loading template: %v\n", err) + return + } + + router.GET("/", func(c *gin.Context) { + configLock.RLock() + domain := config.Domain + configLock.RUnlock() + + data := struct { + Domain string + }{ + Domain: domain, + } + + if err := tmpl.Execute(c.Writer, data); err != nil { + c.String(http.StatusInternalServerError, fmt.Sprintf("Error rendering template: %v", err)) + } + }) router.NoRoute(handler) - err := router.Run(fmt.Sprintf("%s:%d", host, port)) + err = router.Run(fmt.Sprintf("%s:%d", host, port)) if err != nil { fmt.Printf("Error starting server: %v\n", err) } diff --git a/public/index.html b/public/index.html index 5b212cd..f21cc26 100644 --- a/public/index.html +++ b/public/index.html @@ -11,18 +11,18 @@ - + - + - + \ No newline at end of file