refactor: update app instance structure to include both mailserver and logger

This commit is contained in:
2024-08-18 13:35:07 +07:00
parent 7df02c270b
commit d64a4a587e
23 changed files with 147 additions and 225 deletions

View File

@ -3,21 +3,15 @@ package middleware
import (
"context"
"fmt"
"github.com/fossyy/filekeeper/app"
"net/http"
"strings"
errorHandler "github.com/fossyy/filekeeper/handler/error"
"github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/session"
"github.com/fossyy/filekeeper/utils"
)
var log *logger.AggregatedLogger
func init() {
log = logger.Logger()
}
type wrapper struct {
http.ResponseWriter
request *http.Request
@ -64,7 +58,7 @@ func Handler(next http.Handler) http.Handler {
writer.Header().Set("Access-Control-Allow-Methods", fmt.Sprintf("%s, OPTIONS", utils.Getenv("CORS_METHODS")))
writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
next.ServeHTTP(wrappedWriter, request)
log.Info(fmt.Sprintf("%s %s %s %v", utils.ClientIP(request), request.Method, request.RequestURI, wrappedWriter.statusCode))
app.Server.Logger.Info(fmt.Sprintf("%s %s %s %v", utils.ClientIP(request), request.Method, request.RequestURI, wrappedWriter.statusCode))
})
}