Skip to content

Commit

Permalink
Release v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanmehrotra authored Mar 6, 2024
2 parents f9212a3 + 2a4b4e7 commit fd52bcd
Show file tree
Hide file tree
Showing 38 changed files with 1,288 additions and 115 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ jobs:
run: |
go mod download
- name: Create Kafka topics for test
run: |
docker exec ${{ job.services.kafka.id }} kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic products
docker exec ${{ job.services.kafka.id }} kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic order-logs
- name: Start Zipkin
run: docker run -d -p 2005:9411 openzipkin/zipkin:latest

Expand Down Expand Up @@ -157,7 +152,8 @@ jobs:
run: |
export GOFR_ENV=test
go test gofr.dev/pkg/... -tags migration -v -short -coverprofile packageWithMigration.cov -coverpkg=gofr.dev/pkg/...
grep -v 'gofr.dev/pkg/gofr/migration' packageWithMigration.cov > profile.cov
grep -v 'gofr.dev/pkg/gofr/migration' packageWithMigration.cov > packageWithoutMigration.cov
grep -v 'google/mock_interfaces\.go' packageWithoutMigration.cov > profile.cov
go tool cover -func profile.cov
- name: Upload Test Coverage
Expand Down Expand Up @@ -221,7 +217,6 @@ jobs:
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 Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ We will focus ourselves towards deployment in kubernetes and aspire to provide o

1. Simple API syntax
2. REST Standards by default
3. [Configuration management](https://gofr.dev/docs/v1/references/configs)
3. Configuration management
4. Inbuilt Middlewares
5. [Error Management](https://gofr.dev/docs/v1/references/errors)
6. [gRPC support](https://gofr.dev/docs/v1/advanced-guide/grpc)
5. [gRPC support](https://gofr.dev/docs/advanced-guide/grpc)
6. [HTTP service](https://gofr.dev/docs/advanced-guide/http-communication) with support for [Circuit Breaker](https://gofr.dev/docs/advanced-guide/circuit-breaker) and
[Health Check](https://gofr.dev/docs/advanced-guide/monitoring-service-health)

## 👍 Contribute
If you want to say thank you and/or support the active development of GoFr:
Expand Down
123 changes: 123 additions & 0 deletions docs/advanced-guide/grpc/page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# gRPC
We have already seen how GoFr can help ease the development of HTTP servers, but there are
cases where performance is primiraliy required sacrificing flexibility. In these types of
scenarios gRPC protocol comes into picture. gRPC is an open-source RPC(Remote Procedure Call)
framework initially developed by Google. [Learn more](https://grpc.io/docs/what-is-grpc/introduction/)

## Prerequisites
- Install the `protoc` protocol buffer compilation
- Linux, using `apt` or `apt-get`
```shell
$ apt install -y protobuf-compiler
$ protoc --version # Ensure compiler version is 3+
```
- MacOS, using homebrew
```shell
$ brew install protobuf
$ protoc --version # Ensure compiler version is 3+
```
- Install **Go Puligins** for protocol compiler:
1. Install prtocol compiler plugins for Go
```shell
$ go install google.golang.org/protobuf/cmd/[email protected]
$ go install google.golang.org/grpc/cmd/[email protected]
```
2. Update `PATH` for `protoc` compiler to find the plugins:
```shell
$ export PATH="$PATH:$(go env GOPATH)/bin"
```

## Creating protocol buffers
For a detailed guide, please take a look at the [Tutorial](https://grpc.io/docs/languages/go/basics/) at official gRPC docs.

Fistly, we need to create a `customer.proto` file to define our service and the rpc methods that the service provides.
```protobuf
// Indicates the protocol buffer version that is being used
syntax = "proto3";
// Indicates the go package where the generated file will be produced
option go_package = "";
service CustomerService {
// ...
}
```
Inside the service one can define all the `rpc` methods, specifying the request and responses types.
```protobuf
service CustomerService {
// GetCustomer is a rpc method to get customer data using specific filters
rpc GetCustomer(CustomerFilter) returns(CustomerData) {}
}
```
The `CustomerFilter` and `CustomerData` are two types of messages that will be exchanged between server
and client. Users must define those for protocol buffer to serialize them when making a remote procedure call.
```protobuf
syntax = "proto3";
message CustomerFilter {
int64 id = 1;
string name = 2;
// other fields that can be passed
}
message CustomerData {
int64 id = 1;
string name = 2;
string address = 3;
// other customer releated fields
}
```

Now run the following command to gegnerate go code using the Go gRPC plugins:
```shell
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
customer.proto
```
Above command will generate two files `customer.pb.go` and `customer_grpc.pb.go` and these contain necessary code to perform rpc calls.
In `customer.pb.go` you can find `CustomerService` interface-
```go
// CustomerServiceServer is the server API for CustomerService service.
type CustomerServiceServer interface {
GetCustomer(context.Context, *CustomerFilter) (*CustomerData, error)
}
```
User needs to implement this interface to serve the content to the client calling the method.
```go
package customer
import (
"context"
)
type Handler struct {
// required fields to get the customer data
}
func (h *Handler) GetCustomer(ctx context.Context, filter *CustomerFilter) (*CustomerData, error) {
// get the customer data and handler error
return data, nil
}
```

Lastly to register the gRPC service to the gofr server, user can call the `RegisterCustomerServiceServer` in `customer_grpc.pb.go`
to register the service giving gofr app and the Handler struct.
```go
package main
import (
"gofr.dev/pkg/gofr"
"gofr.dev/examples/grpc-server/customer"
)
func main() {
app := gofr.New()
customer.RegisterCustomerServiceServer(app, customer.Handler{})
app.Run()
}
```
>Note: By default, grpc server will run on port 9000, to customize the port users can set GRPC_PORT config in the .env
2 changes: 1 addition & 1 deletion docs/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const navigation = [
{ title: 'Circuit Breaker Support', href: '/docs/advanced-guide/circuit-breaker' },
{ title: 'Monitoring Service Health', href: '/docs/advanced-guide/monitoring-service-health' },
{ title: 'Handling Data Migrations', href: '/docs/advanced-guide/handling-data-migrations' },
{ title: 'Writing gRPC Server', href: '/docs/advanced-guide/grpc' },
// { title: 'Dealing with Remote Files', href: '/docs/advanced-guide/remote-files' },
// { title: 'Supporting OAuth', href: '/docs/advanced-guide/oauth' },
// { title: 'Writing gRPC Server', href: '/docs/advanced-guide/grpc' },
// { title: 'Creating a Static File Server', href: '/docs/advanced-guide/static-file-server' },
// { title: 'WebSockets', href: '/docs/advanced-guide/websockets' },
],
Expand Down
6 changes: 5 additions & 1 deletion examples/using-migrations/configs/.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ DB_NAME=test
DB_PORT=2001
DB_DIALECT=mysql

PUBSUB_BACKEND=KAFKA
PUBSUB_BROKER=localhost:9092
CONSUMER_ID=test

TRACER_HOST=localhost
TRACER_PORT=2005
TRACER_PORT=2005
1 change: 1 addition & 0 deletions examples/using-migrations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"gofr.dev/examples/using-migrations/migrations"

"gofr.dev/pkg/gofr"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package migrations

import (
"context"

"gofr.dev/pkg/gofr/migration"
)

func createTopicsForStore() migration.Migrate {
return migration.Migrate{
UP: func(d migration.Datasource) error {
err := d.PubSub.CreateTopic(context.Background(), "products")
if err != nil {
return err
}

return d.PubSub.CreateTopic(context.Background(), "order-logs")
},
}
}
1 change: 1 addition & 0 deletions examples/using-migrations/migrations/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ func All() map[int64]migration.Migrate {
return map[int64]migration.Migrate{
1708322067: createTableEmployee(),
1708322089: addEmployeeInRedis(),
1708322090: createTopicsForStore(),
}
}
23 changes: 23 additions & 0 deletions examples/using-migrations/migrations/all_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package migrations

import (
"testing"

"github.com/stretchr/testify/assert"

"gofr.dev/pkg/gofr/migration"
)

func TestAll(t *testing.T) {
// Get the map of migrations
allMigrations := All()

expected := map[int64]migration.Migrate{
1708322067: createTableEmployee(),
1708322089: addEmployeeInRedis(),
1708322090: createTopicsForStore(),
}

// Check if the length of the maps match
assert.Equal(t, len(expected), len(allMigrations), "TestAll Failed!")
}
4 changes: 0 additions & 4 deletions examples/using-publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ package main

import (
"encoding/json"
"fmt"

"gofr.dev/pkg/gofr"
)

func main() {
app := gofr.New()

fmt.Println(app.Config.Get("PUBSUB_BROKER"))

app.POST("/publish-order", order)

app.POST("/publish-product", product)
Expand Down
37 changes: 18 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module gofr.dev
go 1.21

require (
cloud.google.com/go/pubsub v1.36.1
cloud.google.com/go/pubsub v1.36.2
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/alicebob/miniredis/v2 v2.31.1
github.com/go-redis/redismock/v9 v9.2.0
Expand All @@ -13,11 +13,11 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_golang v1.19.0
github.com/redis/go-redis/extra/redisotel/v9 v9.0.5
github.com/redis/go-redis/v9 v9.5.1
github.com/segmentio/kafka-go v0.4.47
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.49.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
go.opentelemetry.io/otel v1.24.0
Expand All @@ -28,17 +28,17 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
go.uber.org/mock v0.4.0
golang.org/x/term v0.17.0
google.golang.org/api v0.160.0
golang.org/x/term v0.18.0
google.golang.org/api v0.166.0
google.golang.org/grpc v1.61.1
google.golang.org/protobuf v1.32.0
)

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand All @@ -52,32 +52,31 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/googleapis/gax-go/v2 v2.12.1 // indirect
github.com/klauspost/compress v1.16.6 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/openzipkin/zipkin-go v0.4.2 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/yuin/gopher-lua v1.1.0 // indirect
go.einride.tech/aip v0.66.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240116215550-a9fa1716bcac // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit fd52bcd

Please sign in to comment.