mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
update readme.md
This commit is contained in:
parent
53e115242a
commit
50cfd64db8
2 changed files with 87 additions and 85 deletions
|
|
@ -22,7 +22,7 @@
|
||||||
- 支持Git clone,raw,realeases等文件拉取
|
- 支持Git clone,raw,realeases等文件拉取
|
||||||
- 支持多个前端主题
|
- 支持多个前端主题
|
||||||
- 支持自定义黑名单/白名单
|
- 支持自定义黑名单/白名单
|
||||||
- 支持Git Clone缓存(配合组件)
|
- 支持Git Clone缓存(配合[Smart-Git](https://github.com/WJQSERVER-STUDIO/smart-git))
|
||||||
- 支持Docker部署
|
- 支持Docker部署
|
||||||
- 支持速率限制
|
- 支持速率限制
|
||||||
- 支持用户鉴权
|
- 支持用户鉴权
|
||||||
|
|
@ -62,6 +62,8 @@ git clone https://ghproxy.1888866.xyz/https://github.com/WJQSERVER-STUDIO/ghprox
|
||||||
|
|
||||||
## 部署说明
|
## 部署说明
|
||||||
|
|
||||||
|
可参考文章: https://blog.wjqserver.com/post/ghproxy-deploy-with-smart-git/
|
||||||
|
|
||||||
### Docker部署
|
### Docker部署
|
||||||
|
|
||||||
- Docker-cli
|
- Docker-cli
|
||||||
|
|
@ -184,6 +186,8 @@ url = "socks5://127.0.0.1:1080" # "http://127.0.0.1:7890" 支持Socks5/HTTP(S)
|
||||||
|
|
||||||
### 前端页面
|
### 前端页面
|
||||||
|
|
||||||
|
参看[GHProxy-Frontend](https://github.com/WJQSERVER-STUDIO/GHProxy-Frontend)
|
||||||
|
|
||||||
#### Bootstrap主题
|
#### Bootstrap主题
|
||||||

|

|
||||||

|

|
||||||
|
|
|
||||||
166
main.go
166
main.go
|
|
@ -156,7 +156,7 @@ func InitReq(cfg *config.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadEmbeddedPages 加载嵌入式页面资源
|
// loadEmbeddedPages 加载嵌入式页面资源
|
||||||
func loadEmbeddedPages(cfg *config.Config) (fs.FS, error) {
|
func loadEmbeddedPages(cfg *config.Config) (fs.FS, fs.FS, error) {
|
||||||
var pages fs.FS
|
var pages fs.FS
|
||||||
var err error
|
var err error
|
||||||
switch cfg.Pages.Theme {
|
switch cfg.Pages.Theme {
|
||||||
|
|
@ -178,125 +178,123 @@ func loadEmbeddedPages(cfg *config.Config) (fs.FS, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load embedded pages: %w", err)
|
return nil, nil, fmt.Errorf("failed to load embedded pages: %w", err)
|
||||||
}
|
}
|
||||||
return pages, nil
|
|
||||||
|
var assets fs.FS
|
||||||
|
assets, err = fs.Sub(pagesFS, "pages/assets")
|
||||||
|
return pages, assets, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupPages 设置页面路由
|
// setupPages 设置页面路由
|
||||||
func setupPages(cfg *config.Config, r *server.Hertz) {
|
func setupPages(cfg *config.Config, r *server.Hertz) {
|
||||||
switch cfg.Pages.Mode {
|
switch cfg.Pages.Mode {
|
||||||
case "internal":
|
case "internal":
|
||||||
// 加载嵌入式资源
|
err := setInternalRoute(cfg, r)
|
||||||
pages, err := loadEmbeddedPages(cfg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logError("Failed when processing internal pages: %s", err)
|
logError("Failed when processing internal pages: %s", err)
|
||||||
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置嵌入式资源路由
|
|
||||||
r.GET("/", func(ctx context.Context, c *app.RequestContext) {
|
|
||||||
staticServer := http.FileServer(http.FS(pages))
|
|
||||||
req, err := adaptor.GetCompatRequest(&c.Request)
|
|
||||||
if err != nil {
|
|
||||||
logError("%s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
|
||||||
})
|
|
||||||
r.GET("/favicon.ico", func(ctx context.Context, c *app.RequestContext) {
|
|
||||||
staticServer := http.FileServer(http.FS(pages))
|
|
||||||
req, err := adaptor.GetCompatRequest(&c.Request)
|
|
||||||
if err != nil {
|
|
||||||
logError("%s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
|
||||||
})
|
|
||||||
r.GET("/script.js", func(ctx context.Context, c *app.RequestContext) {
|
|
||||||
staticServer := http.FileServer(http.FS(pages))
|
|
||||||
req, err := adaptor.GetCompatRequest(&c.Request)
|
|
||||||
if err != nil {
|
|
||||||
logError("%s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
|
||||||
})
|
|
||||||
r.GET("/style.css", func(ctx context.Context, c *app.RequestContext) {
|
|
||||||
staticServer := http.FileServer(http.FS(pages))
|
|
||||||
req, err := adaptor.GetCompatRequest(&c.Request)
|
|
||||||
if err != nil {
|
|
||||||
logError("%s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
|
||||||
})
|
|
||||||
|
|
||||||
case "external":
|
case "external":
|
||||||
// 设置外部资源路径
|
// 设置外部资源路径
|
||||||
indexPagePath := fmt.Sprintf("%s/index.html", cfg.Pages.StaticDir)
|
indexPagePath := fmt.Sprintf("%s/index.html", cfg.Pages.StaticDir)
|
||||||
faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Pages.StaticDir)
|
faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Pages.StaticDir)
|
||||||
javascriptsPath := fmt.Sprintf("%s/script.js", cfg.Pages.StaticDir)
|
javascriptsPath := fmt.Sprintf("%s/script.js", cfg.Pages.StaticDir)
|
||||||
stylesheetsPath := fmt.Sprintf("%s/style.css", cfg.Pages.StaticDir)
|
stylesheetsPath := fmt.Sprintf("%s/style.css", cfg.Pages.StaticDir)
|
||||||
//bootstrapPath := fmt.Sprintf("%s/bootstrap.min.css", cfg.Pages.StaticDir)
|
bootstrapPath := fmt.Sprintf("%s/bootstrap.min.css", cfg.Pages.StaticDir)
|
||||||
|
bootstrapBundlePath := fmt.Sprintf("%s/bootstrap.bundle.min.js", cfg.Pages.StaticDir)
|
||||||
|
|
||||||
// 设置外部资源路由
|
// 设置外部资源路由
|
||||||
r.StaticFile("/", indexPagePath)
|
r.StaticFile("/", indexPagePath)
|
||||||
r.StaticFile("/favicon.ico", faviconPath)
|
r.StaticFile("/favicon.ico", faviconPath)
|
||||||
r.StaticFile("/script.js", javascriptsPath)
|
r.StaticFile("/script.js", javascriptsPath)
|
||||||
r.StaticFile("/style.css", stylesheetsPath)
|
r.StaticFile("/style.css", stylesheetsPath)
|
||||||
|
r.StaticFile("/bootstrap.min.css", bootstrapPath)
|
||||||
|
r.StaticFile("/bootstrap.bundle.min.js", bootstrapBundlePath)
|
||||||
//router.StaticFile("/bootstrap.min.css", bootstrapPath)
|
//router.StaticFile("/bootstrap.min.css", bootstrapPath)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// 处理无效的Pages Mode
|
// 处理无效的Pages Mode
|
||||||
logWarning("Invalid Pages Mode: %s, using default embedded theme", cfg.Pages.Mode)
|
logWarning("Invalid Pages Mode: %s, using default embedded theme", cfg.Pages.Mode)
|
||||||
|
|
||||||
// 加载嵌入式资源
|
err := setInternalRoute(cfg, r)
|
||||||
pages, err := loadEmbeddedPages(cfg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logError("Failed when processing pages: %s", err)
|
logError("Failed when processing internal pages: %s", err)
|
||||||
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 设置嵌入式资源路由
|
|
||||||
r.GET("/", func(ctx context.Context, c *app.RequestContext) {
|
|
||||||
staticServer := http.FileServer(http.FS(pages))
|
|
||||||
req, err := adaptor.GetCompatRequest(&c.Request)
|
|
||||||
if err != nil {
|
|
||||||
logError("%s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
|
||||||
})
|
|
||||||
r.GET("/favicon.ico", func(ctx context.Context, c *app.RequestContext) {
|
|
||||||
staticServer := http.FileServer(http.FS(pages))
|
|
||||||
req, err := adaptor.GetCompatRequest(&c.Request)
|
|
||||||
if err != nil {
|
|
||||||
logError("%s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
|
||||||
})
|
|
||||||
r.GET("/script.js", func(ctx context.Context, c *app.RequestContext) {
|
|
||||||
staticServer := http.FileServer(http.FS(pages))
|
|
||||||
req, err := adaptor.GetCompatRequest(&c.Request)
|
|
||||||
if err != nil {
|
|
||||||
logError("%s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
|
||||||
})
|
|
||||||
r.GET("/style.css", func(ctx context.Context, c *app.RequestContext) {
|
|
||||||
staticServer := http.FileServer(http.FS(pages))
|
|
||||||
req, err := adaptor.GetCompatRequest(&c.Request)
|
|
||||||
if err != nil {
|
|
||||||
logError("%s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setInternalRoute(cfg *config.Config, r *server.Hertz) error {
|
||||||
|
|
||||||
|
// 加载嵌入式资源
|
||||||
|
pages, assets, err := loadEmbeddedPages(cfg)
|
||||||
|
if err != nil {
|
||||||
|
logError("Failed when processing pages: %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// 设置嵌入式资源路由
|
||||||
|
r.GET("/", func(ctx context.Context, c *app.RequestContext) {
|
||||||
|
staticServer := http.FileServer(http.FS(pages))
|
||||||
|
req, err := adaptor.GetCompatRequest(&c.Request)
|
||||||
|
if err != nil {
|
||||||
|
logError("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
||||||
|
})
|
||||||
|
r.GET("/favicon.ico", func(ctx context.Context, c *app.RequestContext) {
|
||||||
|
staticServer := http.FileServer(http.FS(pages))
|
||||||
|
req, err := adaptor.GetCompatRequest(&c.Request)
|
||||||
|
if err != nil {
|
||||||
|
logError("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
||||||
|
})
|
||||||
|
r.GET("/script.js", func(ctx context.Context, c *app.RequestContext) {
|
||||||
|
staticServer := http.FileServer(http.FS(pages))
|
||||||
|
req, err := adaptor.GetCompatRequest(&c.Request)
|
||||||
|
if err != nil {
|
||||||
|
logError("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
||||||
|
})
|
||||||
|
r.GET("/style.css", func(ctx context.Context, c *app.RequestContext) {
|
||||||
|
staticServer := http.FileServer(http.FS(pages))
|
||||||
|
req, err := adaptor.GetCompatRequest(&c.Request)
|
||||||
|
if err != nil {
|
||||||
|
logError("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
||||||
|
})
|
||||||
|
r.GET("/bootstrap.min.css", func(ctx context.Context, c *app.RequestContext) {
|
||||||
|
staticServer := http.FileServer(http.FS(assets))
|
||||||
|
req, err := adaptor.GetCompatRequest(&c.Request)
|
||||||
|
if err != nil {
|
||||||
|
logError("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
||||||
|
})
|
||||||
|
r.GET("/bootstrap.bundle.min.js", func(ctx context.Context, c *app.RequestContext) {
|
||||||
|
staticServer := http.FileServer(http.FS(assets))
|
||||||
|
req, err := adaptor.GetCompatRequest(&c.Request)
|
||||||
|
if err != nil {
|
||||||
|
logError("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
staticServer.ServeHTTP(adaptor.GetCompatResponseWriter(&c.Response), req)
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
readFlag()
|
readFlag()
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue