Skip to content

Commit 3e33e2f

Browse files
committed
feat(api): update metrics endpoint to /api/v1/metrics for better versioning
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
1 parent d2b4b5b commit 3e33e2f

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

cmd/api/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func main() {
5555
app.Use(middleware.Compress())
5656
app.Use(middleware.CORS())
5757
app.Use(middleware.RateLimit())
58-
app.Use("/metrics", middleware.Monitor())
58+
app.Use("/api/v1/metrics", middleware.Monitor())
5959

6060
// ###############################################################################
6161
// Router Setup and Server Startup

internal/constants/constants.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ const (
2828
)
2929

3030
// Available years for stock data
31-
var AvailableYears = []string{"2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023"}
31+
var AvailableYears = []string{"2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023"}
32+
33+
// Monitor titles
34+
const (
35+
MonitorTitleAr = "لوحة مراقبة نقاء"
36+
MonitorTitleEn = "NAQA Monitoring Dashboard"
37+
)

internal/handlers/handlers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (h *Handler) ApiV1Handler(c *fiber.Ctx) error {
4949
"endpoints": []string{
5050
"/api/v1/stocks",
5151
"/api/v1/health",
52+
"/api/v1/metrics",
5253
},
5354
})
5455
}

internal/middleware/middleware.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package middleware
22

33
import (
4+
"fmt"
45
"time"
56

7+
"github.com/anqorithm/naqa-api/internal/constants"
68
"github.com/gofiber/fiber/v2"
79
"github.com/gofiber/fiber/v2/middleware/compress"
810
"github.com/gofiber/fiber/v2/middleware/cors"
@@ -54,11 +56,12 @@ func RateLimit() fiber.Handler {
5456
})
5557
}
5658

57-
// Monitor returns an enhanced dashboard monitoring middleware
59+
// Monitor returns a monitor middleware
5860
func Monitor() fiber.Handler {
59-
return monitor.New(monitor.Config{
60-
Title: "Naqa API - System Metrics",
61-
Refresh: 3 * time.Second, // Refresh metrics every 3 seconds
62-
APIOnly: true, // Monitor only API routes
63-
})
64-
}
61+
return monitor.New(monitor.Config{
62+
Title: fmt.Sprintf("%s | %s", constants.MonitorTitleAr, constants.MonitorTitleEn),
63+
Refresh: 3 * time.Second,
64+
Next: nil,
65+
APIOnly: false,
66+
})
67+
}

internal/seeders/seeders.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package seeders
22

3+
// ###############################################################################
4+
// Stock Data Seeder
5+
// ###############################################################################
6+
37
import (
48
"context"
59
"encoding/json"

internal/utils/utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package utils
22

3+
// ###############################################################################
4+
// Utility Functions
5+
// ###############################################################################
6+
37
import (
48
"fmt"
59

610
"github.com/go-playground/validator/v10"
711
)
812

13+
// SafeString converts an interface to a string
914
func SafeString(v interface{}) string {
1015
switch val := v.(type) {
1116
case string:
@@ -19,6 +24,7 @@ func SafeString(v interface{}) string {
1924
}
2025
}
2126

27+
// ValidateRequest validates the request using the validator package
2228
var validate *validator.Validate
2329

2430
func init() {

0 commit comments

Comments
 (0)