-
Notifications
You must be signed in to change notification settings - Fork 15
/
error.go
46 lines (38 loc) 路 1.21 KB
/
error.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 handler
import (
"html/template"
"net/http"
"github.com/number571/go-peer/cmd/hidden_lake/applications/messenger/internal/config"
hlm_settings "github.com/number571/go-peer/cmd/hidden_lake/applications/messenger/pkg/settings"
"github.com/number571/go-peer/cmd/hidden_lake/applications/messenger/web"
"github.com/number571/go-peer/pkg/logger"
http_logger "github.com/number571/go-peer/internal/logger/http"
)
type sError struct {
*sTemplate
FTitle string
FMessage string
}
func ErrorPage(pLogger logger.ILogger, pCfg config.IConfig, pTitle, pMessage string) http.HandlerFunc {
return func(pW http.ResponseWriter, pR *http.Request) {
logBuilder := http_logger.NewLogBuilder(hlm_settings.CServiceName, pR)
pW.WriteHeader(http.StatusNotFound)
t, err := template.ParseFS(
web.GetTemplatePath(),
"index.html",
"error.html",
)
if err != nil {
panic("can't load hmtl files")
}
pLogger.PushWarn(logBuilder.WithMessage(pTitle))
_ = t.Execute(pW, &sError{
sTemplate: getTemplate(pCfg),
FTitle: pTitle,
FMessage: pMessage,
})
}
}
func NotFoundPage(pLogger logger.ILogger, pCfg config.IConfig) http.HandlerFunc {
return ErrorPage(pLogger, pCfg, "404_page", "page not found")
}