forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path404_handler.go
46 lines (41 loc) · 938 Bytes
/
404_handler.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
46
package uadmin
import (
"net/http"
"strconv"
)
// pageErrorHandler is handler to return 404 pages
func pageErrorHandler(w http.ResponseWriter, r *http.Request, session *Session) {
type Context struct {
User string
ID uint
UserExists bool
Language Language
SiteName string
ErrMsg string
ErrCode int
RootURL string
Logo string
FavIcon string
}
c := Context{}
c.RootURL = RootURL
c.SiteName = SiteName
c.Language = getLanguage(r)
c.ErrMsg = "Page Not Found"
c.ErrCode = 404
c.Logo = Logo
c.FavIcon = FavIcon
if r.Form.Get("err_msg") != "" {
c.ErrMsg = r.Form.Get("err_msg")
}
if code, err := strconv.ParseUint(r.Form.Get("err_code"), 10, 16); err == nil {
c.ErrCode = int(code)
}
if session != nil {
user := session.User
c.User = user.Username
c.ID = user.ID
}
w.WriteHeader(c.ErrCode)
RenderHTML(w, r, "./templates/uadmin/"+Theme+"/404.html", c)
}