-
Notifications
You must be signed in to change notification settings - Fork 6
/
notfound.go
45 lines (40 loc) · 1.08 KB
/
notfound.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2012 by sdm. All rights reserved.
// license that can be found in the LICENSE file.
package wk
import (
"net/http"
"strings"
)
// NotFoundResult is wrap of http 404
type NotFoundResult struct {
}
// Execute return 404 to client
func (r *NotFoundResult) Execute(ctx *HttpContext) error {
/*
text/plain; text/html; text/*;
text/html,application/xhtml+xml,application/xml;
*/
if ctx.Server.Config.NotFoundPageEnable {
accetps := ctx.Accept()
if strings.Contains(accetps, "text/html") {
if f := ctx.Server.MapPath("public/404.html"); isFileExists(f) {
http.ServeFile(ctx.Resonse, ctx.Request, f)
return nil
}
if ctx.Server.Config.ViewEnable {
if f := ctx.Server.MapPath("views/404.html"); isFileExists(f) {
ctx.ViewData["ctx"] = ctx
return executeViewFile("404.html", ctx)
}
}
}
if strings.Contains(accetps, "text/plain") {
if f := ctx.Server.MapPath("public/404.txt"); isFileExists(f) {
http.ServeFile(ctx.Resonse, ctx.Request, f)
return nil
}
}
}
http.Error(ctx.Resonse, msgNotFound, http.StatusNotFound)
return nil
}