Skip to content

Commit

Permalink
feat(api): update metrics endpoint to /api/v1/metrics for better vers…
Browse files Browse the repository at this point in the history
…ioning

feat(constants): add monitor titles in Arabic and English for localization
refactor(middleware): enhance Monitor middleware to use localized titles
docs(seeders): add comments for stock data seeder for better clarity
docs(utils): add comments for utility functions for better understanding
  • Loading branch information
Abdullah Alqahtani committed Dec 28, 2024
1 parent d2b4b5b commit 3e33e2f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {
app.Use(middleware.Compress())
app.Use(middleware.CORS())
app.Use(middleware.RateLimit())
app.Use("/metrics", middleware.Monitor())
app.Use("/api/v1/metrics", middleware.Monitor())

// ###############################################################################
// Router Setup and Server Startup
Expand Down
8 changes: 7 additions & 1 deletion internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ const (
)

// Available years for stock data
var AvailableYears = []string{"2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023"}
var AvailableYears = []string{"2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023"}

// Monitor titles
const (
MonitorTitleAr = "لوحة مراقبة نقاء"
MonitorTitleEn = "NAQA Monitoring Dashboard"
)
1 change: 1 addition & 0 deletions internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (h *Handler) ApiV1Handler(c *fiber.Ctx) error {
"endpoints": []string{
"/api/v1/stocks",
"/api/v1/health",
"/api/v1/metrics",
},
})
}
Expand Down
17 changes: 10 additions & 7 deletions internal/middleware/middleware.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package middleware

import (
"fmt"
"time"

"github.com/anqorithm/naqa-api/internal/constants"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/gofiber/fiber/v2/middleware/cors"
Expand Down Expand Up @@ -54,11 +56,12 @@ func RateLimit() fiber.Handler {
})
}

// Monitor returns an enhanced dashboard monitoring middleware
// Monitor returns a monitor middleware
func Monitor() fiber.Handler {
return monitor.New(monitor.Config{
Title: "Naqa API - System Metrics",
Refresh: 3 * time.Second, // Refresh metrics every 3 seconds
APIOnly: true, // Monitor only API routes
})
}
return monitor.New(monitor.Config{
Title: fmt.Sprintf("%s | %s", constants.MonitorTitleAr, constants.MonitorTitleEn),
Refresh: 3 * time.Second,
Next: nil,
APIOnly: false,
})
}
4 changes: 4 additions & 0 deletions internal/seeders/seeders.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package seeders

// ###############################################################################
// Stock Data Seeder
// ###############################################################################

import (
"context"
"encoding/json"
Expand Down
6 changes: 6 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package utils

// ###############################################################################
// Utility Functions
// ###############################################################################

import (
"fmt"

"github.com/go-playground/validator/v10"
)

// SafeString converts an interface to a string
func SafeString(v interface{}) string {
switch val := v.(type) {
case string:
Expand All @@ -19,6 +24,7 @@ func SafeString(v interface{}) string {
}
}

// ValidateRequest validates the request using the validator package
var validate *validator.Validate

func init() {
Expand Down

0 comments on commit 3e33e2f

Please sign in to comment.