Skip to content

Commit aae7488

Browse files
authored
Merge pull request #1440 from gofr-dev/release/v1.32.0
Release/v1.32.0
2 parents fc8616b + 81557c9 commit aae7488

File tree

191 files changed

+3033
-1186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+3033
-1186
lines changed

Diff for: .github/workflows/go.yml

+13-36
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,12 @@ jobs:
111111
run: |
112112
go mod download
113113
114-
- name: Test and Count Warnings
114+
- name: Test
115115
run: |
116116
export APP_ENV=test
117-
warning_count=$(go test gofr.dev/pkg/... -v -short -coverprofile package.cov -coverpkg=gofr.dev/pkg/... | tee /dev/tty | grep -c "WARNING" || true)
117+
go test gofr.dev/pkg/... -v -short -coverprofile package.cov -coverpkg=gofr.dev/pkg/...
118118
grep -v '/mock_' package.cov > profile.cov
119-
codeCoverage=$(go tool cover -func profile.cov | awk '/total/ {print substr($3, 1, length($3)-1)}')
120-
echo "Warnings found: $warning_count"
121-
echo "warning_count=$warning_count" >> $GITHUB_ENV
122-
echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV
123-
124-
- name: Fail if too many warnings
125-
run: |
126-
if [ ${{ env.warning_count }} -gt 10 ]; then
127-
echo "Too many warnings: ${{ env.warning_count }}"
128-
exit 1
129-
fi
119+
go tool cover -func profile.cov
130120
131121
- name: Upload Test Coverage
132122
if: ${{ matrix.go-version == '1.22'}}
@@ -162,13 +152,11 @@ jobs:
162152
codeCoverage=${codeCoverage%?}
163153
echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV
164154
165-
# - name: Check if code-coverage is greater than threshold
166-
# run: |
167-
# codeCoverage=${{ env.CODE_COVERAGE }}
168-
# if (( $(echo "$codeCoverage < 92" | bc -l) )); then
169-
# echo "code coverage cannot be less than 92%, currently its $codeCoverage%"
170-
# exit 1
171-
# fi
155+
# - name: Check if code-coverage is greater than threshold
156+
# run: |
157+
# codeCoverage=${{ env.CODE_COVERAGE }}
158+
# codeCoverage=${codeCoverage%??}
159+
# if [[ $codeCoverage -lt 92 ]]; then echo "code coverage cannot be less than 92%, currently its ${{ env.CODE_COVERAGE }}%" && exit 1; fi;
172160
Submodule-Unit-Testing:
173161
name: Submodule Unit Testing (v${{ matrix.go-version }})🛠
174162
runs-on: ubuntu-latest
@@ -204,25 +192,14 @@ jobs:
204192
205193
# Run tests for the submodule and generate coverage
206194
export APP_ENV=test
207-
warning_count=$(go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./... | tee /dev/tty | grep -c "WARNING" || true)
208-
total_warning_count=$((total_warning_count + warning_count))
195+
go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./...
209196
210197
# Return to the root directory
211198
cd -
212199
done
213-
214-
echo "Total warnings found: $total_warning_count"
215-
echo "total_warning_count=$total_warning_count" >> $GITHUB_ENV
216-
217-
- name: Fail if too many warnings
218-
run: |
219-
if [ ${{ env.total_warning_count }} -gt 10 ]; then
220-
echo "Too many warnings: ${{ env.total_warning_count }}"
221-
exit 1
222-
fi
223200
224201
- name: Upload Coverage Reports
225-
uses: actions/upload-artifact@v3
202+
uses: actions/upload-artifact@v4
226203
with:
227204
name: coverage-reports
228205
path: pkg/**/*.cov
@@ -247,7 +224,7 @@ jobs:
247224
run: |
248225
awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./Example-Test-Report/profile.cov > merged_profile.cov
249226
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
250-
227+
251228
- name: Upload
252229
uses: paambaati/[email protected]
253230
env:
@@ -271,7 +248,7 @@ jobs:
271248

272249
- name: Get dependencies
273250
run: |
274-
go mod tidy
251+
go mod tidy
275252
276253
- name: Lint Root Module
277254
uses: golangci/golangci-lint-action@v3
@@ -309,4 +286,4 @@ jobs:
309286
- name: Check for file names errors
310287
uses: ls-lint/[email protected]
311288
with:
312-
config: .ls-lint.yml
289+
config: .ls-lint.yml

Diff for: .golangci.yml

+13
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ linters-settings:
5454
allow-unused: false # report any unused nolint directives
5555
require-explanation: true # require an explanation for nolint directives
5656
require-specific: true # require nolint directives to be specific about which linter is being skipped
57+
usestdlibvars:
58+
time-layout: true # Suggest the use of constants available in time package
5759
revive:
5860
rules:
5961
# default revive rules, they have to be present otherwise they are disabled
@@ -66,6 +68,12 @@ linters-settings:
6668
- name: error-return
6769
- name: error-strings
6870
- name: errorf
71+
- name: exported
72+
arguments:
73+
# enables checking public methods of private types
74+
- "checkPrivateReceivers"
75+
# make error messages clearer
76+
- "sayRepetitiveInsteadOfStutters"
6977
- name: increment-decrement
7078
- name: indent-error-flow
7179
- name: range
@@ -86,6 +94,7 @@ linters-settings:
8694
- name: defer
8795
- name: deep-exit
8896
- name: unused-receiver
97+
- name: use-any
8998

9099
linters:
91100
# please, do not use `enable-all`: it's deprecated and will be removed soon.
@@ -94,6 +103,7 @@ linters:
94103
enable:
95104
- asciicheck
96105
- bodyclose
106+
- canonicalheader
97107
- copyloopvar
98108
- dogsled
99109
- dupl
@@ -143,6 +153,9 @@ linters:
143153
# - testpackage # We also need to do unit test for unexported functions. And adding _internal in all files is cumbersome.
144154

145155
issues:
156+
include:
157+
- EXC0014
158+
146159
# exclude-use-default: false
147160
# exclude-use-default: false # By default, golangci-lint does not enforce comments on exported types. We want it.
148161
# Excluding configuration per-path, per-linter, per-text and per-source

Diff for: CONTRIBUTING.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ docker run --name kafka-1 -p 9092:9092 \
8181
bitnami/kafka:3.4
8282
docker pull scylladb/scylla
8383
docker run --name scylla -d -p 2025:9042 scylladb/scylla
84+
docker pull surrealdb/surrealdb:latest
85+
docker run --name surrealdb -d -p 8000:8000 surrealdb/surrealdb:latest start --bind 0.0.0.0:8000
8486

8587

8688

@@ -116,7 +118,7 @@ Please note that the recommended local port for the services are different than
116118
* After adding or modifying code existing code, update the documentation too - [development/docs](https://github.com/gofr-dev/gofr/tree/development/docs).
117119
* When you consider a new documentation page is needed, start by adding a new file and writing your new documentation. Then - add a reference to it in [navigation.js](https://gofr.dev/docs/navigation.js).
118120
* If needed, update or add proper code examples for your changes.
119-
* In case images are needed, add it to [docs/public](https://gofr.dev/docs/public) folder.
121+
* In case images are needed, add it to [docs/public](./docs/public) folder.
120122
* Make sure you don't break existing links and references.
121123
* Maintain Markdown standards, you can read more [here](https://www.markdownguide.org/basic-syntax/), this includes:
122124
- Headings (`#`, `##`, etc.) should be placed in order.

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import "gofr.dev/pkg/gofr"
7878
func main() {
7979
app := gofr.New()
8080

81-
app.GET("/greet", func(ctx *gofr.Context) (interface{}, error) {
81+
app.GET("/greet", func(ctx *gofr.Context) (any, error) {
8282
return "Hello World!", nil
8383
})
8484

Diff for: docs/advanced-guide/grpc/page.md

+24-25
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
We have already seen how GoFr can help ease the development of HTTP servers, but there are cases where performance is primarily required sacrificing flexibility. In these types of scenarios gRPC protocol comes into picture. {% new-tab-link title="gRPC" href="https://grpc.io/docs/what-is-grpc/introduction/" /%} is an open-source RPC(Remote Procedure Call) framework initially developed by Google.
44

5-
GoFr simplifies creating gRPC servers and enables efficient tracing across inter-service calls, leveraging its context for seamless data access and trace management in your handlers.
5+
GoFr streamlines the creation of gRPC servers and clients with unified GoFr's context support.
6+
It provides built-in tracing, metrics, and logging to ensure seamless performance monitoring for both
7+
gRPC servers and inter-service gRPC communication. Using GoFr's context, you can easily define custom metrics and
8+
traces across gRPC handlers, enabling consistent observability and simplified debugging throughout your system.
69

710
## Prerequisites
811

@@ -11,30 +14,30 @@ GoFr simplifies creating gRPC servers and enables efficient tracing across inter
1114
- **Linux (using `apt` or `apt-get`):**
1215

1316
```bash
14-
sudo apt install -y protobuf-compiler
15-
protoc --version # Ensure compiler version is 3+
17+
sudo apt install -y protobuf-compiler
18+
protoc --version # Ensure compiler version is 3+
1619
```
1720

1821
- **macOS (using Homebrew):**
1922

2023
```bash
21-
brew install protobuf
22-
protoc --version # Ensure compiler version is 3+
24+
brew install protobuf
25+
protoc --version # Ensure compiler version is 3+
2326
```
2427

2528
**2. Go Plugins for Protocol Compiler:**
2629

2730
a. Install protocol compiler plugins for Go:
2831

2932
```bash
30-
go install google.golang.org/protobuf/cmd/[email protected]
31-
go install google.golang.org/grpc/cmd/[email protected]
33+
go install google.golang.org/protobuf/cmd/[email protected]
34+
go install google.golang.org/grpc/cmd/[email protected]
3235
```
3336

3437
b. Update `PATH` for `protoc` to locate the plugins:
3538

3639
```bash
37-
export PATH="$PATH:$(go env GOPATH)/bin"
40+
export PATH="$PATH:$(go env GOPATH)/bin"
3841
```
3942

4043
## Creating Protocol Buffers
@@ -81,12 +84,12 @@ string address = 3;
8184
Run the following command to generate Go code using the Go gRPC plugins:
8285

8386
```bash
84-
protoc \
85-
--go_out=. \
86-
--go_opt=paths=source_relative \
87-
--go-grpc_out=. \
88-
--go-grpc_opt=paths=source_relative \
89-
{serviceName}.proto
87+
protoc \
88+
--go_out=. \
89+
--go_opt=paths=source_relative \
90+
--go-grpc_out=. \
91+
--go-grpc_opt=paths=source_relative \
92+
{serviceName}.proto
9093
```
9194

9295
This command generates two files, `{serviceName}.pb.go` and `{serviceName}_grpc.pb.go`, containing the necessary code for performing RPC calls.
@@ -95,20 +98,16 @@ This command generates two files, `{serviceName}.pb.go` and `{serviceName}_grpc.
9598
To install the CLI -
9699

97100
```bash
98-
go install gofr.dev/cli/gofr@latest
101+
go install gofr.dev/cli/gofr@latest
99102
```
100103

101104
## Generating gRPC Server Handler Template using `gofr wrap grpc server`
102105

103106
**1. Use the `gofr wrap grpc server` Command:**
104107
```bash
105-
gofr wrap grpc server -proto=./path/your/proto/file
108+
gofr wrap grpc server -proto=./path/your/proto/file
106109
```
107110

108-
```bash
109-
gofr wrap grpc -proto=./path/your/proto/file
110-
```
111-
112111
This command leverages the `gofr-cli` to generate a `{serviceName}_server.go` file (e.g., `customer_server.go`)
113112
containing a template for your gRPC server implementation, including context support, in the same directory as
114113
that of the specified proto file.
@@ -138,7 +137,7 @@ import (
138137
func main() {
139138
app := gofr.New()
140139

141-
packageName.Register{serviceName}ServerWithGofr(app, &packageName.{serviceName}GoFrServer{})
140+
packageName.Register{serviceName}ServerWithGofr(app, &{packageName}.{serviceName}GoFrServer{})
142141

143142
app.Run()
144143
}
@@ -150,7 +149,7 @@ func main() {
150149

151150
**1. Use the `gofr wrap grpc client` Command:**
152151
```bash
153-
gofr wrap grpc client -proto=./path/your/proto/file
152+
gofr wrap grpc client -proto=./path/your/proto/file
154153
```
155154
This command leverages the `gofr-cli` to generate a `{serviceName}_client.go` file (e.g., `customer_client.go`). This file must not be modified.
156155

@@ -160,7 +159,7 @@ This command leverages the `gofr-cli` to generate a `{serviceName}_client.go` fi
160159
// gRPC Handler with context support
161160
func {serviceMethod}(ctx *gofr.Context) (*{serviceResponse}, error) {
162161
// Create the gRPC client
163-
srv, err := New{serviceName}GoFrClient("your-grpc-server-host")
162+
srv, err := New{serviceName}GoFrClient("your-grpc-server-host", ctx.Metrics())
164163
if err != nil {
165164
return nil, err
166165
}
@@ -170,7 +169,7 @@ req := &{serviceRequest}{
170169
// populate fields as necessary
171170
}
172171

173-
// Call the gRPC method with tracing enabled
172+
// Call the gRPC method with tracing/metrics enabled
174173
res, err := srv.{serviceMethod}(ctx, req)
175174
if err != nil {
176175
return nil, err
@@ -179,4 +178,4 @@ return nil, err
179178
return res, nil
180179
}
181180
```
182-
> ##### Check out the example of setting up a gRPC server in GoFr: [Visit GitHub](https://github.com/gofr-dev/gofr/blob/main/examples/grpc-server/main.go)
181+
> ##### Check out the example of setting up a gRPC server/client in GoFr: [Visit GitHub](https://github.com/gofr-dev/gofr/tree/main/examples/grpc)

Diff for: docs/advanced-guide/http-communication/page.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -99,35 +99,35 @@ GoFr provides its user with additional configurational options while registering
9999
#### Usage:
100100

101101
```go
102-
a.AddHTTPService("cat-facts", "https://catfact.ninja",
103-
&service.APIKeyConfig{APIKey: "some-random-key"},
104-
105-
&service.BasicAuthConfig{
106-
UserName: "gofr",
107-
Password: "gofr",
102+
a.AddHTTPService("cat-facts", "https://catfact.ninja",
103+
&service.APIKeyConfig{APIKey: "some-random-key"},
104+
105+
&service.BasicAuthConfig{
106+
UserName: "gofr",
107+
Password: "gofr",
108+
},
109+
110+
&service.CircuitBreakerConfig{
111+
Threshold: 4,
112+
Interval: 1 * time.Second,
108113
},
109-
110-
&service.CircuitBreakerConfig{
111-
Threshold: 4,
112-
Interval: 1 * time.Second,
113-
},
114-
115-
&service.DefaultHeaders{Headers: map[string]string{"key": "value"}},
116-
117-
&service.HealthConfig{
118-
HealthEndpoint: "breeds",
119-
},
120-
121-
&service.OAuthConfig{
122-
ClientID: "abc",
123-
ClientSecret: "abc",
124-
TokenURL: "http://test.com",
125-
Scopes: nil,
126-
EndpointParams: nil,
114+
115+
&service.DefaultHeaders{Headers: map[string]string{"key": "value"}},
116+
117+
&service.HealthConfig{
118+
HealthEndpoint: "breeds",
127119
},
128-
120+
121+
&service.OAuthConfig{
122+
ClientID: "abc",
123+
ClientSecret: "abc",
124+
TokenURL: "http://test.com",
125+
Scopes: nil,
126+
EndpointParams: nil,
127+
},
128+
129129
&service.RetryConfig{
130130
MaxRetries: 5
131-
},
131+
},
132132
)
133133
```

0 commit comments

Comments
 (0)