- Created main application entry point in `main.go`. - Added configuration management in `config/config.go` and tests in `config/config_test.go`. - Implemented handlers for book and stationery uploads in `handlers/book.go` and `handlers/stationery.go`, including validation logic. - Established database connection and services in `services/database.go` and `services/book_service.go`. - Defined models for books and stationery in `models/book.go` and `models/stationery.go`. - Set up Firebase integration for image uploads in `services/firebase.go`. - Created migration scripts for database schema in `migrations/001_create_tables.sql` and subsequent updates. - Added CORS and error handling middleware. - Included comprehensive tests for handlers, services, and utilities. - Documented API endpoints and usage in `README.md` and migration instructions in `migrations/README.md`. - Introduced `.gitignore` to exclude unnecessary files and directories. - Added Go module support with `go.mod` and `go.sum` files. - Implemented utility functions for slug generation and validation in `utils/slug.go` and `utils/validation.go`.
45 lines
925 B
Go
45 lines
925 B
Go
package middleware
|
|
|
|
import (
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
|
)
|
|
|
|
// SetupLogger configures request logging middleware
|
|
func SetupLogger() fiber.Handler {
|
|
return logger.New(logger.Config{
|
|
Format: "${time} ${status} - ${latency} ${method} ${path} ${ip}\n",
|
|
TimeFormat: "2006-01-02 15:04:05",
|
|
TimeZone: "Local",
|
|
Output: nil, // Use default (stdout)
|
|
})
|
|
}
|
|
|
|
// CustomLogger is a more detailed logger with structured output
|
|
func CustomLogger() fiber.Handler {
|
|
return func(c *fiber.Ctx) error {
|
|
start := time.Now()
|
|
|
|
// Process request
|
|
err := c.Next()
|
|
|
|
// Calculate latency
|
|
latency := time.Since(start)
|
|
|
|
// Log request details
|
|
log.Printf("[%s] %s %s | Status: %d | Latency: %v | IP: %s",
|
|
time.Now().Format("2006-01-02 15:04:05"),
|
|
c.Method(),
|
|
c.Path(),
|
|
c.Response().StatusCode(),
|
|
latency,
|
|
c.IP(),
|
|
)
|
|
|
|
return err
|
|
}
|
|
}
|