feat(*): go 后端项目脚手架

This commit is contained in:
2025-11-15 18:20:30 +08:00
commit 5bb025c1aa
39 changed files with 2459 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package handler
import (
"io"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/zhilv666/navsite/pkg/common"
)
func Proxy(c *gin.Context) {
_url := c.Query("url")
if _url == "" {
common.Fail(c, "missing url")
return
}
// 请求目标 URL
resp, err := http.Get(_url)
if err != nil {
common.Fail(c, "unable to fetch image")
return
}
defer resp.Body.Close()
// 检查 Content-Type 是否为图片
contentType := resp.Header.Get("Content-Type")
if !strings.HasPrefix(contentType, "image/") {
common.Fail(c, "not an image file")
return
}
// 设置响应 Content-Type
c.Writer.Header().Set("Content-Type", contentType)
// 将图片数据直接写入响应
_, err = io.Copy(c.Writer, resp.Body)
if err != nil {
common.Fail(c, "failed to write image")
return
}
}