Skip to content

Commit 5bc6ec2

Browse files
authored
Merge pull request #1327 from gofr-dev/release/1.29.0
Release/1.29.0
2 parents 16de8ae + a6c406f commit 5bc6ec2

File tree

40 files changed

+733
-319
lines changed

40 files changed

+733
-319
lines changed

.github/workflows/go.yml

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-latest
2222
strategy:
2323
matrix:
24-
go-version: ['1.22', '1.21']
24+
go-version: ['1.23', '1.22']
2525

2626
services:
2727
kafka:
@@ -157,6 +157,53 @@ jobs:
157157
# codeCoverage=${{ env.CODE_COVERAGE }}
158158
# codeCoverage=${codeCoverage%??}
159159
# if [[ $codeCoverage -lt 92 ]]; then echo "code coverage cannot be less than 92%, currently its ${{ env.CODE_COVERAGE }}%" && exit 1; fi;
160+
Submodule-Unit-Testing:
161+
name: Submodule Unit Testing (v${{ matrix.go-version }})🛠
162+
runs-on: ubuntu-latest
163+
strategy:
164+
matrix:
165+
go-version: [ '1.23', '1.22' ]
166+
167+
steps:
168+
- name: Checkout code into go module directory
169+
uses: actions/checkout@v4
170+
with:
171+
fetch-depth: 0
172+
173+
- name: Set up Go ${{ matrix.go-version }}
174+
uses: actions/setup-go@v5
175+
with:
176+
go-version: ${{ matrix.go-version }}
177+
id: Go
178+
179+
- name: Detect and Test Submodules
180+
run: |
181+
# Find all directories containing a go.mod file within 'pkg'
182+
for module in $(find pkg -name "go.mod" -exec dirname {} \;); do
183+
echo "Testing module: $module"
184+
cd $module
185+
186+
# Extract module name (replace '/' with '_')
187+
module_name=$(echo $module | tr '/' '_')
188+
189+
# Download dependencies for the submodule
190+
go mod download
191+
go mod tidy
192+
193+
# Run tests for the submodule and generate coverage
194+
export APP_ENV=test
195+
go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./...
196+
197+
# Return to the root directory
198+
cd -
199+
done
200+
201+
- name: Upload Coverage Reports
202+
uses: actions/upload-artifact@v3
203+
with:
204+
name: coverage-reports
205+
path: pkg/**/*.cov
206+
160207

161208
upload_coverage:
162209
name: Upload Coverage📊
@@ -195,9 +242,20 @@ jobs:
195242
uses: actions/checkout@v4
196243
- name: Get dependencies
197244
run: go get -v -t -d ./...
198-
- name: GolangCI-Lint
245+
- name: Lint Root Module
199246
run: |
247+
echo "Linting root module..."
200248
golangci-lint run --timeout 9m0s
249+
- name: Lint Submodules
250+
run: |
251+
echo "Searching for submodules..."
252+
for module in $(find pkg -name "go.mod" -exec dirname {} \;); do
253+
echo "Linting submodule: $module"
254+
cd $module
255+
go mod tidy
256+
golangci-lint run --timeout 9m0s
257+
cd -
258+
done
201259
202260
linting_party:
203261
name: Linting Party🥳

docs/advanced-guide/gofr-errors/page.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ dbErr2 := datasource.ErrorDB{Message : "database connection timed out!"}
4444
GoFr's error structs implements an interface with `Error() string` and `StatusCode() int` methods, users can override the
4545
status code by implementing it for their custom error.
4646

47+
You can optionally define a log level for your error with the `LogLevel() logging.Level` methods
48+
4749
#### Usage:
4850
```go
4951
type customError struct {
@@ -57,4 +59,8 @@ func (c customError) Error() string {
5759
func (c customError) StatusCode() int {
5860
return http.StatusMethodNotAllowed
5961
}
62+
63+
func (c customError) LogLevel() logging.Level {
64+
return logging.WARN
65+
}
6066
```
Lines changed: 95 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,118 @@
1-
# Setting Custom Response Headers
1+
# Custom Response Headers and Metadata in GoFr
22

3-
In GoFr, you can customize HTTP response headers using the `Response` struct, allowing you to add extra information to
4-
responses sent from your application. This feature can be useful for adding metadata, such as custom headers, security
5-
policies, or other contextual information, to improve the client-server communication.
3+
GoFr simplifies the process of adding custom HTTP response headers and metadata to API responses using the `Response` struct. This feature allows you to include additional information such as custom headers or metadata to enhance client-server communication while keeping your data payload clean and structured.
64

7-
## Using the Response Struct
5+
## Features
86

9-
To use custom headers in your handler, create and return a Response object within the handler function. This object
10-
should contain the response data along with a Headers map for any custom headers you wish to add.
7+
1. **Custom Headers**: Add key-value pairs for headers, useful for:
8+
- Security policies
9+
- Debugging information
10+
- Versioning details
1111

12-
### Example:
12+
**Type**: `map[string]string`
13+
- Keys and values must be strings.
1314

14-
Below is an example showing how to use the Response struct in a GoFr handler. In this case, the `HelloHandler` function
15-
returns a greeting message along with two custom headers: X-Custom-Header and X-Another-Header.
15+
2. **Metadata**: Include optional contextual information like:
16+
- Deployment environment
17+
- Request-specific details (e.g., timestamps, tracing IDs)
18+
19+
**Type**: `map[string]any`
20+
- Keys must be strings, and values can be of any type.
21+
22+
When metadata is included, the response structure is:
23+
```json
24+
{
25+
"data": {},
26+
"metadata": {}
27+
}
28+
```
29+
30+
If metadata is omitted, the response defaults to:
31+
32+
```json
33+
{
34+
"data": {}
35+
}
36+
```
37+
38+
### Example Usage
39+
40+
#### Adding Custom Headers and Metadata
41+
To include custom headers and metadata in your response, populate the Headers and MetaData fields of the Response struct in your handler function.
1642

1743
```go
1844
package main
1945

2046
import (
21-
"gofr.dev/pkg/gofr"
22-
"gofr.dev/pkg/gofr/http/response"
47+
"time"
48+
49+
"gofr.dev/pkg/gofr"
50+
"gofr.dev/pkg/gofr/http/response"
2351
)
2452

2553
func main() {
26-
// Create a new application
27-
a := gofr.New()
54+
app := gofr.New()
2855

29-
// Add the route
30-
a.GET("/hello", HelloHandler)
56+
app.GET("/hello", HelloHandler)
3157

32-
// Run the application
33-
a.Run()
58+
app.Run()
3459
}
3560

3661
func HelloHandler(c *gofr.Context) (interface{}, error) {
37-
name := c.Param("name")
38-
if name == "" {
39-
c.Log("Name came empty")
40-
name = "World"
41-
}
42-
43-
headers := map[string]string{
44-
"X-Custom-Header": "CustomValue",
45-
"X-Another-Header": "AnotherValue",
46-
}
47-
48-
return response.Response{
49-
Data: "Hello World from new Server",
50-
Headers: headers,
51-
}, nil
62+
name := c.Param("name")
63+
if name == "" {
64+
c.Log("Name parameter is empty, defaulting to 'World'")
65+
name = "World"
66+
}
67+
68+
// Define custom headers (map[string]string)
69+
headers := map[string]string{
70+
"X-Custom-Header": "CustomValue",
71+
"X-Another-Header": "AnotherValue",
72+
}
73+
74+
// Define metadata (map[string]any)
75+
metaData := map[string]any{
76+
"environment": "staging",
77+
"timestamp": time.Now(),
78+
}
79+
80+
// Return response with custom headers and metadata
81+
return response.Response{
82+
Data: map[string]string{"message": "Hello, " + name + "!"},
83+
Metadata: metaData,
84+
Headers: headers,
85+
}, nil
5286
}
5387
```
5488

89+
### Example Responses
90+
#### Response with Metadata:
91+
When metadata is included, the response contains the metadata field:
92+
93+
```json
94+
{
95+
"data": {
96+
"message": "Hello, World!"
97+
},
98+
"metadata": {
99+
"environment": "staging",
100+
"timestamp": "2024-12-23T12:34:56Z"
101+
}
102+
}
103+
```
104+
105+
#### Response without Metadata:
106+
If no metadata is provided, the response only includes the data field:
107+
108+
```json
109+
{
110+
"data": {
111+
"message": "Hello, World!"
112+
}
113+
}
114+
```
115+
116+
55117
This functionality offers a convenient, structured way to include additional response information without altering the
56118
core data payload.

docs/quick-start/connecting-redis/page.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ Following configuration keys are required for Redis connectivity:
3737
* `REDIS_PORT`: It specifies the port number on which your Redis server is listening. The default Redis port is 6379.
3838
* `REDIS_USER` : This is the user you'll use to connect to your Redis server. You can configure multiple users with different permissions in a single Redis container. For more details, refer to the [official docs](https://redis.io/docs/latest/operate/oss_and_stack/management/security/acl/)
3939
* `REDIS_PASSWORD`: The password is required only if your Redis server is configured for authentication; if authentication is not enabled, no password is necessary.
40+
* `REDIS_DB`: The database number to use for the Redis server. The default value is 0.
4041
```dotenv
4142
APP_NAME=test-service
4243
HTTP_PORT=9000
4344
4445
REDIS_HOST=localhost
4546
REDIS_PORT=6379
4647
REDIS_PASSWORD=password
48+
REDIS_DB=2
4749
```
4850

4951
The following code snippet demonstrates how to retrieve data from a Redis key named "greeting":

docs/references/configs/page.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ This document lists all the configuration options supported by the GoFr framewor
205205
- REDIS_PORT
206206
- Port of the Redis server.
207207

208+
---
209+
210+
- REDIS_USER
211+
- Username for the Redis server.
212+
213+
---
214+
215+
- REDIS_PASSWORD
216+
- Password for the Redis server.
217+
218+
---
219+
220+
- REDIS_DB
221+
- Database number to use for the Redis server.
222+
208223
{% /table %}
209224

210225
### Pub/Sub
@@ -253,6 +268,24 @@ This document lists all the configuration options supported by the GoFr framewor
253268

254269
---
255270

271+
- KAFKA_BATCH_SIZE
272+
- Number of messages to batch before sending to Kafka
273+
- 1
274+
275+
---
276+
277+
- KAFKA_BATCH_BYTES
278+
- Number of bytes to batch before sending to Kafka
279+
- 1048576
280+
281+
---
282+
283+
- KAFKA_BATCH_TIMEOUT
284+
- Time to wait before sending a batch to Kafka
285+
- 100ms
286+
287+
---
288+
256289
- CONSUMER_ID
257290
- Unique identifier for this consumer
258291
- gofr-consumer

examples/using-add-filestore/go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ require (
7878
go.opentelemetry.io/otel/sdk/metric v1.30.0 // indirect
7979
go.opentelemetry.io/otel/trace v1.32.0 // indirect
8080
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
81-
golang.org/x/crypto v0.29.0 // indirect
81+
golang.org/x/crypto v0.31.0 // indirect
8282
golang.org/x/net v0.31.0 // indirect
8383
golang.org/x/oauth2 v0.24.0 // indirect
84-
golang.org/x/sync v0.9.0 // indirect
85-
golang.org/x/sys v0.27.0 // indirect
86-
golang.org/x/term v0.26.0 // indirect
87-
golang.org/x/text v0.20.0 // indirect
84+
golang.org/x/sync v0.10.0 // indirect
85+
golang.org/x/sys v0.28.0 // indirect
86+
golang.org/x/term v0.27.0 // indirect
87+
golang.org/x/text v0.21.0 // indirect
8888
golang.org/x/time v0.8.0 // indirect
8989
google.golang.org/api v0.209.0 // indirect
9090
google.golang.org/genproto v0.0.0-20241113202542-65e8d215514f // indirect

examples/using-add-filestore/go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
254254
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
255255
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
256256
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
257-
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
258-
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
257+
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
258+
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
259259
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
260260
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
261261
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@@ -293,8 +293,8 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
293293
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
294294
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
295295
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
296-
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
297-
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
296+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
297+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
298298
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
299299
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
300300
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -309,24 +309,24 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
309309
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
310310
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
311311
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
312-
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
313-
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
312+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
313+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
314314
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
315315
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
316316
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
317317
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
318318
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
319-
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
320-
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
319+
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
320+
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
321321
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
322322
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
323323
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
324324
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
325325
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
326326
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
327327
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
328-
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
329-
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
328+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
329+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
330330
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
331331
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
332332
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

0 commit comments

Comments
 (0)