mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
1.1 KiB
1.1 KiB
Audit package primer
The audit package is responsible for initialising and providing a configured zap.Logger to other packages.
Overview
During application startup, the logger configuration is loaded from config.GlobalConfig. When audit.Init() is called, an Auditor instance containing the configured zap.Logger is returned. This Auditor is then propagated through middleware to various handler functions.
The audit package is initialised in main.go as follows:
auditor, err := audit.Init(config.GlobalConfig.InDevelopment)
if err != nil {
log.Fatalf("Failed to initialize audit logger: %v", err)
}
log.Println("Audit logger initialized")
Propagation through middleware and handlers
The initialised Auditor is passed to the middleware.DefineRoutes function that sets up all application routes.
router := middleware.DefineRoutes(auditor)
Handlers that require the configured zap.Logger are wrapped using WrapWithAuditor, providing each handler with the Auditor instance.
router.HandleFunc("/users/{id}", CatchError(WrapWithAuditor(auditor, routes.UserPage))).Methods("GET")