Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
4f8750d4
authored
2018-12-21 16:30:34 +0800
by
张磊
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
a89f14d8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
staticfile.go
staticfile.go
View file @
4f8750d
...
...
@@ -18,6 +18,7 @@ import (
"net/http"
"os"
"path"
"path/filepath"
"strconv"
"strings"
...
...
@@ -68,17 +69,26 @@ func serverStaticRouter(ctx *context.Context) {
if
!
DirectoryIndex
{
exception
(
"403"
,
ctx
)
return
}
else
if
ctx
.
Input
.
Request
.
URL
.
Path
[
len
(
ctx
.
Input
.
Request
.
URL
.
Path
)
-
1
]
!=
'/'
{
http
.
Redirect
(
ctx
.
ResponseWriter
,
ctx
.
Request
,
ctx
.
Input
.
Request
.
URL
.
Path
+
"/"
,
302
)
}
else
if
ctx
.
Input
.
Request
.
URL
.
Path
[
len
(
ctx
.
Input
.
Request
.
URL
.
Path
)
-
1
]
!=
'/'
{
http
.
Redirect
(
ctx
.
ResponseWriter
,
ctx
.
Request
,
ctx
.
Input
.
Request
.
URL
.
Path
+
"/"
,
302
)
return
}
}
else
if
strings
.
HasSuffix
(
requestPath
,
"/index.html"
)
{
file
:=
path
.
Join
(
staticDir
,
requestPath
)
if
utils
.
FileExists
(
file
)
{
http
.
ServeFile
(
ctx
.
ResponseWriter
,
ctx
.
Request
,
file
)
//file := path.Join(staticDir, requestPath)
//if utils.FileExists(file) {
//http.ServeFile(ctx.ResponseWriter, ctx.Request, file)
//return
//}
//http.ServeFile can not use index.html
dirName
,
fileName
:=
filepath
.
Split
(
file
)
fs
:=
http
.
Dir
(
dirName
)
f
,
_
:=
fs
.
Open
(
fileName
)
defer
f
.
Close
()
d
,
_
:=
f
.
Stat
()
http
.
ServeContent
(
ctx
.
ResponseWriter
,
ctx
.
Request
,
d
.
Name
(),
d
.
ModTime
(),
f
)
return
}
}
//This block obtained from (https://github.com/smithfox/beego) - it should probably get merged into astaxie/beego after a pull request
isStaticFileToCompress
:=
false
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment