-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1440 from gofr-dev/release/v1.32.0
Release/v1.32.0
- Loading branch information
Showing
191 changed files
with
3,033 additions
and
1,186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'}} | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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: | ||
|
@@ -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 | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
@@ -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. | ||
|
@@ -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. | ||
|
@@ -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() | ||
} | ||
|
@@ -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. | ||
|
||
|
@@ -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 | ||
} | ||
|
@@ -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 | ||
|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.