mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 00:21:56 +08:00
添加favicon支持,更新docker-compose配置以挂载favicon目录,并在主程序中实现favicon.ico处理器,提供自定义favicon功能。
This commit is contained in:
parent
f31c601c20
commit
c04f600332
@ -6,6 +6,7 @@ services:
|
||||
- "3336:3336"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./favicon:/app/favicon
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- OAUTH_CLIENT_ID=your_client_id
|
||||
|
2
favicon/.gitkeep
Normal file
2
favicon/.gitkeep
Normal file
@ -0,0 +1,2 @@
|
||||
# 这个文件确保 favicon 目录被 git 跟踪
|
||||
# 用户可以在这个目录中放置自定义的 favicon.ico 文件
|
32
favicon/README.md
Normal file
32
favicon/README.md
Normal file
@ -0,0 +1,32 @@
|
||||
# Favicon 自定义设置
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 将你的 favicon 文件重命名为 `favicon.ico`
|
||||
2. 放置在这个 `favicon` 目录中
|
||||
3. 重启 proxy-go 服务
|
||||
|
||||
## 支持的文件格式
|
||||
|
||||
- `.ico` 文件(推荐)
|
||||
- `.png` 文件(需要重命名为 favicon.ico)
|
||||
- `.jpg/.jpeg` 文件(需要重命名为 favicon.ico)
|
||||
- `.svg` 文件(需要重命名为 favicon.ico)
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 文件必须命名为 `favicon.ico`
|
||||
- 推荐尺寸:16x16, 32x32, 48x48 像素
|
||||
- 如果没有放置文件,将返回 404(浏览器会使用默认图标)
|
||||
|
||||
## 示例
|
||||
|
||||
```bash
|
||||
# 将你的 favicon 文件复制到这个目录
|
||||
cp your-favicon.ico ./favicon/favicon.ico
|
||||
|
||||
# 重启服务
|
||||
docker-compose restart
|
||||
```
|
||||
|
||||
现在访问 `http://your-domain.com/favicon.ico` 就会显示你的自定义 favicon 了!
|
10
go.mod
10
go.mod
@ -1,15 +1,13 @@
|
||||
module proxy-go
|
||||
|
||||
go 1.24
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.24.4
|
||||
toolchain go1.23.1
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.1
|
||||
github.com/woodchen-ink/go-web-utils v1.0.0
|
||||
golang.org/x/net v0.40.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/woodchen-ink/go-web-utils v1.0.0 // indirect
|
||||
golang.org/x/text v0.25.0 // indirect
|
||||
)
|
||||
require golang.org/x/text v0.25.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -1,7 +1,5 @@
|
||||
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
|
||||
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
||||
github.com/woodchen-ink/go-web-utils v0.0.0-20250621140947-08c57486fe2e h1:k/D90giyDyL5hDPJGGQexqZ423WmZqRUUxc/yQ6E8ws=
|
||||
github.com/woodchen-ink/go-web-utils v0.0.0-20250621140947-08c57486fe2e/go.mod h1:d+L8rZ7xekLnf679XRvfwqpl4M8RCNdWSViaB3GmpnI=
|
||||
github.com/woodchen-ink/go-web-utils v1.0.0 h1:Kybe0ZPhRI4w5FJ4bZdPcepNEKTmbw3to3xLR31e+ws=
|
||||
github.com/woodchen-ink/go-web-utils v1.0.0/go.mod h1:hpiT30rd5Egj2LqRwYBqbEtUXjhjh/Qary0S14KCZgw=
|
||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||
|
19
main.go
19
main.go
@ -129,6 +129,25 @@ func main() {
|
||||
matcher func(*http.Request) bool
|
||||
handler http.Handler
|
||||
}{
|
||||
// favicon.ico 处理器
|
||||
{
|
||||
matcher: func(r *http.Request) bool {
|
||||
return r.URL.Path == "/favicon.ico"
|
||||
},
|
||||
handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// 检查是否有自定义favicon文件
|
||||
faviconPath := "favicon/favicon.ico"
|
||||
if _, err := os.Stat(faviconPath); err == nil {
|
||||
// 设置正确的Content-Type和缓存头
|
||||
w.Header().Set("Content-Type", "image/x-icon")
|
||||
w.Header().Set("Cache-Control", "public, max-age=31536000") // 1年缓存
|
||||
http.ServeFile(w, r, faviconPath)
|
||||
} else {
|
||||
// 如果没有自定义favicon,返回404
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}),
|
||||
},
|
||||
// 管理路由处理器
|
||||
{
|
||||
matcher: func(r *http.Request) bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user