mirror of
https://github.com/duanhf2012/origin.git
synced 2026-05-13 19:27:32 +08:00
静态资源get不需要过滤路由
This commit is contained in:
@@ -130,6 +130,23 @@ func (slf *HttpServerService) staticServer(w http.ResponseWriter, r *http.Reques
|
|||||||
w.Write([]byte(msg))
|
w.Write([]byte(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nowpath, _ := os.Getwd()
|
||||||
|
upath := r.URL.Path
|
||||||
|
destLocalPath := nowpath + upath
|
||||||
|
switch r.Method {
|
||||||
|
//获取资源
|
||||||
|
case "GET":
|
||||||
|
//判断文件夹是否存在
|
||||||
|
_, err := os.Stat(destLocalPath)
|
||||||
|
if err == nil {
|
||||||
|
http.ServeFile(w, r, destLocalPath)
|
||||||
|
} else {
|
||||||
|
writeResp(http.StatusNotFound, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//上传资源
|
||||||
|
case "POST":
|
||||||
|
|
||||||
// 在这儿处理例外路由接口
|
// 在这儿处理例外路由接口
|
||||||
var errRet error
|
var errRet error
|
||||||
for _, filter := range slf.httpfiltrateList {
|
for _, filter := range slf.httpfiltrateList {
|
||||||
@@ -147,22 +164,6 @@ func (slf *HttpServerService) staticServer(w http.ResponseWriter, r *http.Reques
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nowpath, _ := os.Getwd()
|
|
||||||
upath := r.URL.Path
|
|
||||||
destLocalPath := nowpath + upath
|
|
||||||
switch r.Method {
|
|
||||||
//获取资源
|
|
||||||
case "GET":
|
|
||||||
//判断文件夹是否存在
|
|
||||||
_, err := os.Stat(destLocalPath)
|
|
||||||
if err == nil {
|
|
||||||
http.ServeFile(w, r, destLocalPath)
|
|
||||||
} else {
|
|
||||||
writeResp(http.StatusNotFound, "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//上传资源
|
|
||||||
case "POST":
|
|
||||||
r.ParseMultipartForm(32 << 20) // max memory is set to 32MB
|
r.ParseMultipartForm(32 << 20) // max memory is set to 32MB
|
||||||
resourceFile, resourceFileHeader, err := r.FormFile("file")
|
resourceFile, resourceFileHeader, err := r.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -190,6 +191,7 @@ func (slf *HttpServerService) staticServer(w http.ResponseWriter, r *http.Reques
|
|||||||
defer localfd.Close()
|
defer localfd.Close()
|
||||||
|
|
||||||
io.Copy(localfd, resourceFile)
|
io.Copy(localfd, resourceFile)
|
||||||
|
|
||||||
writeResp(http.StatusOK, upath+fileName)
|
writeResp(http.StatusOK, upath+fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user