Skip to content

Commit 097bd71

Browse files
docs:adds msguuid to the readme
1 parent 634661f commit 097bd71

File tree

6 files changed

+175
-196
lines changed

6 files changed

+175
-196
lines changed

README.md

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,13 +2868,13 @@ $ curl -X POST http://0.0.0.0:8080/v1/user/maxbody/max \
28682868
## 📜 Logger (Request Logging)
28692869
The `logger` middleware captures HTTP request details, helping with monitoring, debugging, and analytics.
28702870

2871-
#### 🚀 Key Features:
2871+
### 🚀 Key Features:
28722872
- ✅ Logs request method, path, response time, and status code.
28732873
- ✅ Supports multiple formats: text, json, and slog (structured logging).
28742874
- ✅ Helps track API usage and debugging.
28752875
- ✅ Customizable log patterns and additional fields.
28762876

2877-
#### 📝 Default Logging
2877+
### 📝 Default Logging
28782878
This example applies simple logging.
28792879

28802880
```go
@@ -2916,12 +2916,12 @@ Text Logging
29162916
```bash
29172917
$ curl -i -XGET http://localhost:8080/v1/logger
29182918
```
2919-
#### Console:
2919+
### Console:
29202920
![Quick Logger Example](readmeLogs/log.simple.png)
29212921

29222922
---
29232923

2924-
#### 📝 Structured Logging(Text Format)
2924+
### 📝 Structured Logging(Text Format)
29252925
This example applies logging in text format with custom log fields.
29262926

29272927
```go
@@ -2987,7 +2987,7 @@ Text Logging
29872987
```bash
29882988
$ curl -i -XGET http://localhost:8080/v1/logger
29892989
```
2990-
#### Console:
2990+
### Console:
29912991
![Quick Logger Example](readmeLogs/log.format.text.png)
29922992

29932993
---
@@ -3064,7 +3064,7 @@ func main() {
30643064
```bash
30653065
$ curl -i -XGET http://localhost:8080/v1/logger/slog
30663066
```
3067-
#### Console:
3067+
### Console:
30683068
![Quick Logger Example](readmeLogs/log.format.slog.png)
30693069

30703070
---
@@ -3131,9 +3131,84 @@ JSON Logging
31313131
```bash
31323132
$ curl -i -XGET http://localhost:8080/v1/logger/json
31333133
```
3134-
#### Console:
3134+
### Console:
31353135
![Quick Logger Example](readmeLogs/log.format.json.png)
31363136

3137+
---
3138+
## 🆔 MsgUUID Middleware
3139+
3140+
### 📌 Overview
3141+
3142+
The MsgUUID Middleware in Quick is responsible for automatically generating a unique identifier (UUID) for each incoming HTTP request. This identifier is added to the response headers, allowing better tracking, debugging, and log correlation in distributed systems.
3143+
3144+
---
3145+
3146+
### 🚀 How It Works
3147+
The MsgUUID Middleware works by:
3148+
3149+
- Intercepts each incoming HTTP request before processing.
3150+
- Generating a unique UUID for each request.
3151+
- Attaching the generated UUID to the response headers for tracking.
3152+
- Helping log correlation and debugging across distributed systems.
3153+
3154+
---
3155+
3156+
### ✅ Key Features
3157+
3158+
| Feature | Benefit |
3159+
|----------------------------|-------------------------------------------------------------|
3160+
| 🆔 **Unique Identifier** | Adds a UUID to each request for tracking and correlation. |
3161+
| 🔄 **Automatic Generation** | No need for manual UUID creation, added seamlessly. |
3162+
| 📊 **Enhanced Debugging** | Makes log analysis easier by attaching request identifiers. |
3163+
| 🚀 **Lightweight & Fast** | Does not impact performance, operates efficiently. |
3164+
3165+
---
3166+
3167+
This example generates a unique request identifier with the MsgUUUID middleware.
3168+
```go
3169+
package main
3170+
3171+
import (
3172+
"fmt"
3173+
"log"
3174+
3175+
"github.com/jeffotoni/quick"
3176+
"github.com/jeffotoni/quick/middleware/msguuid"
3177+
)
3178+
3179+
func main() {
3180+
q := quick.New()
3181+
3182+
// Apply MsgUUID Middleware globally
3183+
q.Use(msguuid.New())
3184+
3185+
// Define an endpoint that responds with a UUID
3186+
q.Get("/v1/msguuid/default", func(c *quick.Ctx) error {
3187+
c.Set("Content-Type", "application/json")
3188+
3189+
// Log headers to validate UUID presence
3190+
fmt.Println("Headers:", c.Response.Header())
3191+
3192+
// Return a 200 OK status
3193+
return c.Status(200).JSON(nil)
3194+
})
3195+
3196+
log.Fatal(q.Listen("0.0.0.0:8080"))
3197+
}
3198+
```
3199+
### 📌 cURL
3200+
3201+
```bash
3202+
$ curl -i -XGET http://localhost:8080/v1/msguuid/default
3203+
```
3204+
### 📌 Response
3205+
```bash
3206+
"Headers":"map"[
3207+
"Content-Type":["application/json"],
3208+
"Msguuid":[5f49cf4d-b62e-4d81-b46e-5125b52058a6]
3209+
]
3210+
```
3211+
31373212

31383213
---
31393214
## 📚| More Examples

example/middleware/README.md

Lines changed: 6 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -41,133 +41,12 @@ Controls how your API can be accessed from different domains.
4141
---
4242

4343
## 📜 Logger (Request Logging)
44-
The `logger` middleware captures HTTP request details, helping with monitoring, debugging, and analytics.
45-
46-
#### 🚀 Key Features:
47-
- ✅ Logs request method, path, response time, and status code.
48-
- ✅ Supports multiple formats: text, json, and slog (structured logging).
49-
- ✅ Helps track API usage and debugging.
50-
- ✅ Customizable log patterns and additional fields.
51-
52-
#### 📝 Default Logging (Text Format)
53-
This example applies logging in text format with custom log fields.
54-
55-
```go
56-
package main
57-
58-
import (
59-
"github.com/jeffotoni/quick"
60-
"github.com/jeffotoni/quick/middleware/logger"
61-
)
62-
63-
func main() {
64-
65-
q := quick.New()
66-
67-
// Apply the logger middleware with custom configuration
68-
q.Use(logger.New(logger.Config{
69-
Format: "text", // Available formats: "text", "json", "slog"
70-
Pattern: "[${level}] ${ip} ${method} - ${latency} user_id=${user_id} trace=${trace}\n",
71-
Level: "DEBUG", // Logging level: "DEBUG", "INFO", "WARN", "ERROR"
72-
CustomFields: map[string]string{ // Custom fields included in logs
73-
"user_id": "12345",
74-
"trace": "xyz",
75-
},
76-
}))
77-
78-
// Define a route that logs request details
79-
q.Get("/v1/logger", func(c *quick.Ctx) error {
80-
c.Set("Content-Type", "application/json")
81-
82-
// Return a JSON response
83-
return c.Status(200).JSON(quick.M{
84-
"msg": "Quick ❤️",
85-
})
86-
})
87-
88-
// Start the server
89-
q.Listen("0.0.0.0:8080")
90-
}
91-
```
92-
---
93-
### 🛠️ Structured Logging (Slog Format)
94-
95-
This example uses structured logging (slog) for better log parsing.
96-
97-
```go
98-
package main
99-
100-
import (
101-
"github.com/jeffotoni/quick"
102-
"github.com/jeffotoni/quick/middleware/logger"
103-
)
104-
105-
func main() {
106-
107-
q := quick.New()
108-
109-
// Apply logger middleware with structured logging (slog)
110-
q.Use(logger.New(logger.Config{
111-
Format: "slog",
112-
Level: "DEBUG",
113-
Pattern: "[${level}] ${ip} ${method} ${path} - ${latency} " +
114-
"user=${user_id} trace=${trace}\n",
115-
CustomFields: map[string]string{
116-
"user_id": "99999",
117-
"trace": "abcdef",
118-
},
119-
}))
120-
121-
// Define a route with structured logging
122-
q.Get("/v1/logger/slog", func(c *quick.Ctx) error {
123-
c.Set("Content-Type", "application/json")
124-
125-
return c.Status(200).JSON(quick.M{
126-
"msg": "Structured logging with slog",
127-
})
128-
})
129-
130-
// Start the server
131-
q.Listen("0.0.0.0:8080")
132-
}
133-
```
134-
---
135-
### 📦 JSON Logging (Machine-Readable)
136-
137-
Ideal for log aggregation systems, this example logs in JSON format.
138-
139-
```go
140-
package main
141-
142-
import (
143-
"github.com/jeffotoni/quick"
144-
"github.com/jeffotoni/quick/middleware/logger"
145-
)
146-
147-
func main() {
148-
149-
q := quick.New()
150-
151-
// Apply logger with JSON format for structured logging
152-
q.Use(logger.New(logger.Config{
153-
Format: "json",
154-
Level: "INFO",
155-
}))
156-
157-
// Define a logging route
158-
q.Get("/v1/logger/json", func(c *quick.Ctx) error {
159-
c.Set("Content-Type", "application/json")
160-
161-
return c.Status(200).JSON(quick.M{
162-
"msg": "JSON logging example",
163-
})
164-
})
165-
166-
// Start the server
167-
q.Listen("0.0.0.0:8080")
168-
}
44+
The logger middleware captures HTTP request details, helping with monitoring, debugging, and analytics.
16945

170-
```
46+
- Logs request method, path, response time, and status code.
47+
- Supports multiple formats: text, json, and slog (structured logging).
48+
- Helps track API usage and debugging.
49+
- Customizable log patterns and additional fields.
17150

17251
---
17352

@@ -180,7 +59,7 @@ Restricts the maximum request body size to prevent clients from sending excessiv
18059

18160
---
18261

183-
## 🔄 MsgUUID
62+
## 🆔 MsgUUID
18463
Assigns a UUID (Universally Unique Identifier) to each request.
18564

18665
- Allows easy tracking of requests in logs.

example/middleware/msguuid/README.md

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,8 @@ The MsgUUID Middleware works by:
2727

2828
---
2929

30-
### 🔹Attaching a UUID to responses
31-
This example ensures that all responses from the /v1/msguuid/default route contain a unique **UUID.**
30+
This example generates a unique request identifier with the MsgUUUID middleware.
3231

33-
34-
```go
35-
package main
36-
37-
import (
38-
"fmt"
39-
"log"
40-
41-
"github.com/jeffotoni/quick"
42-
"github.com/jeffotoni/quick/middleware/msguuid"
43-
)
44-
45-
func main() {
46-
app := quick.New()
47-
48-
// Enable MsgUUID Middleware
49-
app.Use(msguuid.New())
50-
51-
// Define an endpoint that includes MsgUUID
52-
app.Get("/v1/user", func(c *quick.Ctx) error {
53-
c.Set("Content-Type", "application/json")
54-
55-
// Log the response headers to check the UUID
56-
fmt.Println("Headers:", c.Response.Header())
57-
58-
// Return a 200 OK status with no body
59-
return c.Status(200).JSON(nil)
60-
})
61-
62-
log.Fatal(app.Listen("0.0.0.0:8080"))
63-
}
64-
65-
```
66-
67-
### 📌 Testing with cURL
68-
69-
#### 🔹Sending a GET request
70-
```bash
71-
$ curl -i -X GET http://localhost:8080/v1/user
72-
```
73-
---
74-
75-
### 🔹Default MsgUUID Usage
76-
The following example demonstrates how MsgUUID automatically attaches a **UUID** to every response.
7732
```go
7833
package main
7934

@@ -86,13 +41,13 @@ import (
8641
)
8742

8843
func main() {
89-
app := quick.New()
44+
q := quick.New()
9045

9146
// Apply MsgUUID Middleware globally
92-
app.Use(msguuid.New())
47+
q.Use(msguuid.New())
9348

9449
// Define an endpoint that responds with a UUID
95-
app.Get("/v1/msguuid/default", func(c *quick.Ctx) error {
50+
q.Get("/v1/msguuid/default", func(c *quick.Ctx) error {
9651
c.Set("Content-Type", "application/json")
9752

9853
// Log headers to validate UUID presence
@@ -102,17 +57,20 @@ func main() {
10257
return c.Status(200).JSON(nil)
10358
})
10459

105-
log.Fatal(app.Listen("0.0.0.0:8080"))
60+
log.Fatal(q.Listen("0.0.0.0:8080"))
10661
}
107-
10862
```
63+
### 📌 cURL
10964

110-
### 📌 Testing with cURL
111-
112-
#### 🔹Sending a GET request to the default MsgUUID route
113-
11465
```bash
115-
$ curl -i -X GET http://localhost:8080/v1/msguuid/default
66+
$ curl -i -XGET http://localhost:8080/v1/msguuid/default
67+
```
68+
### 📌 Response
69+
```bash
70+
"Headers":"map"[
71+
"Content-Type":["application/json"],
72+
"Msguuid":[5f49cf4d-b62e-4d81-b46e-5125b52058a6]
73+
]
11674
```
11775
---
11876

@@ -122,7 +80,6 @@ $ curl -i -X GET http://localhost:8080/v1/msguuid/default
12280
- ✅ How It Works: Breakdown of request interception and UUID assignment.
12381
- ✅ Code Examples: How to apply MsgUUID to endpoints.
12482
- ✅ Testing with cURL: Examples of expected response headers.
125-
- ✅ Advantages Table: Summary of benefits.
12683

12784
---
12885

0 commit comments

Comments
 (0)