Skip to content

Commit

Permalink
Merge pull request #1440 from gofr-dev/release/v1.32.0
Browse files Browse the repository at this point in the history
Release/v1.32.0
  • Loading branch information
Umang01-hash authored Jan 27, 2025
2 parents fc8616b + 81557c9 commit aae7488
Show file tree
Hide file tree
Showing 191 changed files with 3,033 additions and 1,186 deletions.
49 changes: 13 additions & 36 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,12 @@ jobs:
run: |
go mod download
- name: Test and Count Warnings
- name: Test
run: |
export APP_ENV=test
warning_count=$(go test gofr.dev/pkg/... -v -short -coverprofile package.cov -coverpkg=gofr.dev/pkg/... | tee /dev/tty | grep -c "WARNING" || true)
go test gofr.dev/pkg/... -v -short -coverprofile package.cov -coverpkg=gofr.dev/pkg/...
grep -v '/mock_' package.cov > profile.cov
codeCoverage=$(go tool cover -func profile.cov | awk '/total/ {print substr($3, 1, length($3)-1)}')
echo "Warnings found: $warning_count"
echo "warning_count=$warning_count" >> $GITHUB_ENV
echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV
- name: Fail if too many warnings
run: |
if [ ${{ env.warning_count }} -gt 10 ]; then
echo "Too many warnings: ${{ env.warning_count }}"
exit 1
fi
go tool cover -func profile.cov
- name: Upload Test Coverage
if: ${{ matrix.go-version == '1.22'}}
Expand Down Expand Up @@ -162,13 +152,11 @@ jobs:
codeCoverage=${codeCoverage%?}
echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV
# - name: Check if code-coverage is greater than threshold
# run: |
# codeCoverage=${{ env.CODE_COVERAGE }}
# if (( $(echo "$codeCoverage < 92" | bc -l) )); then
# echo "code coverage cannot be less than 92%, currently its $codeCoverage%"
# exit 1
# fi
# - name: Check if code-coverage is greater than threshold
# run: |
# codeCoverage=${{ env.CODE_COVERAGE }}
# codeCoverage=${codeCoverage%??}
# if [[ $codeCoverage -lt 92 ]]; then echo "code coverage cannot be less than 92%, currently its ${{ env.CODE_COVERAGE }}%" && exit 1; fi;
Submodule-Unit-Testing:
name: Submodule Unit Testing (v${{ matrix.go-version }})🛠
runs-on: ubuntu-latest
Expand Down Expand Up @@ -204,25 +192,14 @@ jobs:
# Run tests for the submodule and generate coverage
export APP_ENV=test
warning_count=$(go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./... | tee /dev/tty | grep -c "WARNING" || true)
total_warning_count=$((total_warning_count + warning_count))
go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./...
# Return to the root directory
cd -
done
echo "Total warnings found: $total_warning_count"
echo "total_warning_count=$total_warning_count" >> $GITHUB_ENV
- name: Fail if too many warnings
run: |
if [ ${{ env.total_warning_count }} -gt 10 ]; then
echo "Too many warnings: ${{ env.total_warning_count }}"
exit 1
fi
- name: Upload Coverage Reports
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: pkg/**/*.cov
Expand All @@ -247,7 +224,7 @@ jobs:
run: |
awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./Example-Test-Report/profile.cov > merged_profile.cov
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
- name: Upload
uses: paambaati/[email protected]
env:
Expand All @@ -271,7 +248,7 @@ jobs:

- name: Get dependencies
run: |
go mod tidy
go mod tidy
- name: Lint Root Module
uses: golangci/golangci-lint-action@v3
Expand Down Expand Up @@ -309,4 +286,4 @@ jobs:
- name: Check for file names errors
uses: ls-lint/[email protected]
with:
config: .ls-lint.yml
config: .ls-lint.yml
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ linters-settings:
allow-unused: false # report any unused nolint directives
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
usestdlibvars:
time-layout: true # Suggest the use of constants available in time package
revive:
rules:
# default revive rules, they have to be present otherwise they are disabled
Expand All @@ -66,6 +68,12 @@ linters-settings:
- name: error-return
- name: error-strings
- name: errorf
- name: exported
arguments:
# enables checking public methods of private types
- "checkPrivateReceivers"
# make error messages clearer
- "sayRepetitiveInsteadOfStutters"
- name: increment-decrement
- name: indent-error-flow
- name: range
Expand All @@ -86,6 +94,7 @@ linters-settings:
- name: defer
- name: deep-exit
- name: unused-receiver
- name: use-any

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
Expand All @@ -94,6 +103,7 @@ linters:
enable:
- asciicheck
- bodyclose
- canonicalheader
- copyloopvar
- dogsled
- dupl
Expand Down Expand Up @@ -143,6 +153,9 @@ linters:
# - testpackage # We also need to do unit test for unexported functions. And adding _internal in all files is cumbersome.

issues:
include:
- EXC0014

# exclude-use-default: false
# exclude-use-default: false # By default, golangci-lint does not enforce comments on exported types. We want it.
# Excluding configuration per-path, per-linter, per-text and per-source
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ docker run --name kafka-1 -p 9092:9092 \
bitnami/kafka:3.4
docker pull scylladb/scylla
docker run --name scylla -d -p 2025:9042 scylladb/scylla
docker pull surrealdb/surrealdb:latest
docker run --name surrealdb -d -p 8000:8000 surrealdb/surrealdb:latest start --bind 0.0.0.0:8000



Expand Down Expand Up @@ -116,7 +118,7 @@ Please note that the recommended local port for the services are different than
* After adding or modifying code existing code, update the documentation too - [development/docs](https://github.com/gofr-dev/gofr/tree/development/docs).
* 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).
* If needed, update or add proper code examples for your changes.
* In case images are needed, add it to [docs/public](https://gofr.dev/docs/public) folder.
* In case images are needed, add it to [docs/public](./docs/public) folder.
* Make sure you don't break existing links and references.
* Maintain Markdown standards, you can read more [here](https://www.markdownguide.org/basic-syntax/), this includes:
- Headings (`#`, `##`, etc.) should be placed in order.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import "gofr.dev/pkg/gofr"
func main() {
app := gofr.New()

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

Expand Down
49 changes: 24 additions & 25 deletions docs/advanced-guide/grpc/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

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.

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.
GoFr streamlines the creation of gRPC servers and clients with unified GoFr's context support.
It provides built-in tracing, metrics, and logging to ensure seamless performance monitoring for both
gRPC servers and inter-service gRPC communication. Using GoFr's context, you can easily define custom metrics and
traces across gRPC handlers, enabling consistent observability and simplified debugging throughout your system.

## Prerequisites

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

```bash
sudo apt install -y protobuf-compiler
protoc --version # Ensure compiler version is 3+
sudo apt install -y protobuf-compiler
protoc --version # Ensure compiler version is 3+
```

- **macOS (using Homebrew):**

```bash
brew install protobuf
protoc --version # Ensure compiler version is 3+
brew install protobuf
protoc --version # Ensure compiler version is 3+
```

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

a. Install protocol compiler plugins for Go:

```bash
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
```

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

```bash
export PATH="$PATH:$(go env GOPATH)/bin"
export PATH="$PATH:$(go env GOPATH)/bin"
```

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

```bash
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
{serviceName}.proto
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
{serviceName}.proto
```

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

```bash
go install gofr.dev/cli/gofr@latest
go install gofr.dev/cli/gofr@latest
```

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

**1. Use the `gofr wrap grpc server` Command:**
```bash
gofr wrap grpc server -proto=./path/your/proto/file
gofr wrap grpc server -proto=./path/your/proto/file
```

```bash
gofr wrap grpc -proto=./path/your/proto/file
```

This command leverages the `gofr-cli` to generate a `{serviceName}_server.go` file (e.g., `customer_server.go`)
containing a template for your gRPC server implementation, including context support, in the same directory as
that of the specified proto file.
Expand Down Expand Up @@ -138,7 +137,7 @@ import (
func main() {
app := gofr.New()

packageName.Register{serviceName}ServerWithGofr(app, &packageName.{serviceName}GoFrServer{})
packageName.Register{serviceName}ServerWithGofr(app, &{packageName}.{serviceName}GoFrServer{})

app.Run()
}
Expand All @@ -150,7 +149,7 @@ func main() {

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

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

// Call the gRPC method with tracing enabled
// Call the gRPC method with tracing/metrics enabled
res, err := srv.{serviceMethod}(ctx, req)
if err != nil {
return nil, err
Expand All @@ -179,4 +178,4 @@ return nil, err
return res, nil
}
```
> ##### 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)
> ##### 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)
52 changes: 26 additions & 26 deletions docs/advanced-guide/http-communication/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,35 +99,35 @@ GoFr provides its user with additional configurational options while registering
#### Usage:

```go
a.AddHTTPService("cat-facts", "https://catfact.ninja",
&service.APIKeyConfig{APIKey: "some-random-key"},

&service.BasicAuthConfig{
UserName: "gofr",
Password: "gofr",
a.AddHTTPService("cat-facts", "https://catfact.ninja",
&service.APIKeyConfig{APIKey: "some-random-key"},

&service.BasicAuthConfig{
UserName: "gofr",
Password: "gofr",
},

&service.CircuitBreakerConfig{
Threshold: 4,
Interval: 1 * time.Second,
},

&service.CircuitBreakerConfig{
Threshold: 4,
Interval: 1 * time.Second,
},

&service.DefaultHeaders{Headers: map[string]string{"key": "value"}},

&service.HealthConfig{
HealthEndpoint: "breeds",
},

&service.OAuthConfig{
ClientID: "abc",
ClientSecret: "abc",
TokenURL: "http://test.com",
Scopes: nil,
EndpointParams: nil,

&service.DefaultHeaders{Headers: map[string]string{"key": "value"}},

&service.HealthConfig{
HealthEndpoint: "breeds",
},


&service.OAuthConfig{
ClientID: "abc",
ClientSecret: "abc",
TokenURL: "http://test.com",
Scopes: nil,
EndpointParams: nil,
},

&service.RetryConfig{
MaxRetries: 5
},
},
)
```
Loading

0 comments on commit aae7488

Please sign in to comment.