🏗️ Used middleware.Chain in main with LogFmt logger
This commit is contained in:
parent
f9f75f079f
commit
e96380307b
12
main.go
12
main.go
|
@ -28,6 +28,7 @@ import (
|
|||
|
||||
"source.toby3d.me/toby3d/home/internal/common"
|
||||
"source.toby3d.me/toby3d/home/internal/domain"
|
||||
"source.toby3d.me/toby3d/home/internal/middleware"
|
||||
"source.toby3d.me/toby3d/home/internal/page"
|
||||
pagefsrepo "source.toby3d.me/toby3d/home/internal/page/repository/fs"
|
||||
pageucase "source.toby3d.me/toby3d/home/internal/page/usecase"
|
||||
|
@ -81,10 +82,7 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) {
|
|||
themer := themeucase.NewThemeUseCase(themes)
|
||||
pages := pagefsrepo.NewFileSystemPageRepository(contentDir)
|
||||
pager := pageucase.NewPageUseCase(pages, resources)
|
||||
|
||||
server := &http.Server{
|
||||
Addr: config.AddrPort().String(),
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO(toby3d): use exists static use case or split that on static and resource modules?
|
||||
// INFO(toby3d): any static file is public and unprotected by design, so it's safe to search it
|
||||
// first before deep down to any page or it's resource which might be secured by middleware or
|
||||
|
@ -192,7 +190,11 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) {
|
|||
}); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}),
|
||||
})
|
||||
chain := middleware.Chain{middleware.LogFmt()}
|
||||
server := &http.Server{
|
||||
Addr: config.AddrPort().String(),
|
||||
Handler: chain.Handler(handler),
|
||||
ErrorLog: logger,
|
||||
BaseContext: func(ln net.Listener) context.Context { return ctx },
|
||||
WriteTimeout: 500 * time.Millisecond,
|
||||
|
|
Loading…
Reference in New Issue