get_file_handler.go
668 字节
package public
import (
"net/http"
"path/filepath"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func GetFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PublicGetFileRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
handler := http.FileServer(http.Dir("public"))
r.URL.Path = filepath.Join(req.FileName)
handler.ServeHTTP(w, r)
}
}