Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/envoy json transcoder #133

Merged
merged 14 commits into from
May 16, 2020
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# note: call scripts from /scripts

init:
go get -u google.golang.org/grpc \
go get -u github.com/golang/protobuf/protoc-gen-go \
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger

format:
$(call format)

Expand All @@ -22,7 +28,7 @@ sqlboiler:
$(call format)

protogen:
$(call gen_proto_go ,default)
$(call gen_proto_go ,user)
$(call format)

define format
Expand Down Expand Up @@ -64,5 +70,15 @@ define mockgen_repository
endef

define gen_proto_go
$(shell protoc -I${GOPATH}/src --proto_path=./proto --go_out=plugins=grpc:./proto/$1 $1.proto)
$(shell protoc -I${GOPATH}/src \
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/ \
--proto_path=./proto \
--go_out=plugins=grpc:./proto/default \
--include_imports \
--include_source_info \
--descriptor_set_out=./proto/default/$1.pb \
--swagger_out=json_names_for_fields=true:./proto/default \
$1.proto \
)
endef
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ the boilerplate for monorepo application (support only http protocol)

## Apps

| Package | Localhost | Prodction |
| :------------------------------------------------------ | :-------------------- | :------------------- |
| **[[REST] default](./cmd/default)** | http://localhost:8080 | default.\* |
| **[[REST] push-notification](./cmd/push-notification)** | http://localhost:8081 | push-notification.\* |
| Package | Localhost | Prodction |
| :----------------------------------------------------------------- | :--------------------- | :------------------- |
| **[[REST] default](./cmd/default)** | http://localhost:8080 | default.\* |
| **[[gRPC] default-grpc](./cmd/push-notification)** | http://localhost:50051 | default-grpc.\* |
| **[[REST] default-grpc-json-transcoder](./cmd/push-notification)** | http://localhost:51051 | default-grpc-rest.\* |
| **[[REST] push-notification](./cmd/push-notification)** | http://localhost:8081 | push-notification.\* |

## development

Expand Down
4 changes: 2 additions & 2 deletions cmd/default-grpc/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newDefaultServer(logger *zap.Logger, e *environment) *grpc.Server {

userUsecase := usecase.NewUser(userRepository)

defaultHandler := handler.NewDefaultHandler(userUsecase)
userHandler := handler.NewUserHandler(userUsecase)

opts := []grpc_recovery.Option{
grpc_recovery.WithRecoveryHandler(recoveryFuncFactory(logger)),
Expand All @@ -52,7 +52,7 @@ func newDefaultServer(logger *zap.Logger, e *environment) *grpc.Server {
),
)

pb.RegisterDefaultServiceServer(server, defaultHandler)
pb.RegisterUserServiceServer(server, userHandler)
reflection.Register(server)
grpc_health_v1.RegisterHealthServer(server, health.NewServer())

Expand Down
52 changes: 52 additions & 0 deletions deployment/envoy/envoy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }

static_resources:
listeners:
- name: listener1
address:
socket_address: { address: 0.0.0.0, port_value: 51051 }
filter_chains:
- filters:
- name: envoy.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
stat_prefix: grpc_json
codec_type: AUTO
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: grpc, timeout: { seconds: 60 } }
http_filters:
- name: envoy.grpc_json_transcoder
config:
proto_descriptor: "/etc/pb/default/user.pb"
services: ["default.UserService"]
print_options:
add_whitespace: true
always_print_primitive_fields: true
always_print_enums_as_ints: false
preserve_proto_field_names: false
- name: envoy.router
clusters:
- name: grpc
connect_timeout: 1.25s
type: logical_dns
lb_policy: round_robin
dns_lookup_family: V4_ONLY
http2_protocol_options: {}
load_assignment:
cluster_name: grpc
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: default-grpc-server
port_value: 50051
24 changes: 23 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,29 @@ services:
- 8080:8080
volumes:
- .:/go/src/github.com/abyssparanoia/rapid-go
command: ash -c "realize start"
command: ash -c "source .envrc && realize start --name default-server"

default-grpc-server:
build:
context: .
dockerfile: docker/development/Dockerfile
expose:
- 50051
volumes:
- .:/go/src/github.com/abyssparanoia/rapid-go
command: ash -c "source .envrc && realize start --name default-grpc-server"

envoy:
image: envoyproxy/envoy:v1.14.1
volumes:
- "./deployment/envoy:/etc/envoy"
- "./proto:/etc/pb"
expose:
- 51051
ports:
- 51051:51051
links:
- default-grpc-server

default-db:
build: ./db/default
Expand Down
8 changes: 4 additions & 4 deletions docker/development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ COPY . .

ENV GO111MODULE=off

RUN apk --no-cache --update upgrade \
&& apk add --no-cache git alpine-sdk \
&& go get github.com/tockins/realize
RUN apk upgrade \
&& apk add git alpine-sdk \
&& go get -u github.com/tockins/realize

ENV GO111MODULE=on
ENV GO111MODULE=on
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ require (
cloud.google.com/go/firestore v1.1.1
firebase.google.com/go v3.12.1+incompatible
github.com/DATA-DOG/go-sqlmock v1.4.1 // indirect
github.com/bxcodec/faker/v3 v3.3.1
github.com/bxcodec/faker v2.0.1+incompatible
github.com/caarlos0/env/v6 v6.2.2
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
github.com/denisenkom/go-mssqldb v0.0.0-20200206145737-bbfc9a55622e // indirect
github.com/friendsofgo/errors v0.9.2
github.com/go-chi/chi v4.1.1+incompatible
github.com/go-playground/universal-translator v0.17.0 // indirect
Expand All @@ -17,7 +18,7 @@ require (
github.com/go-testfixtures/testfixtures/v3 v3.2.0
github.com/gofrs/uuid v3.2.0+incompatible // indirect
github.com/golang/mock v1.4.3
github.com/golang/protobuf v1.4.1
github.com/golang/protobuf v1.4.2
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/joho/godotenv v1.3.0
github.com/kat-co/vala v0.0.0-20170210184112-42e1d8b61f12
Expand All @@ -29,17 +30,20 @@ require (
github.com/opentracing/opentracing-go v1.1.0
github.com/pkg/errors v0.9.1
github.com/rs/xid v1.2.1
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.0
github.com/uber/jaeger-client-go v2.23.1+incompatible
github.com/uber/jaeger-lib v2.2.0+incompatible // indirect
github.com/unrolled/render v1.0.3
github.com/volatiletech/inflect v0.0.1 // indirect
github.com/volatiletech/null v8.0.0+incompatible
github.com/volatiletech/sqlboiler v3.7.1+incompatible
github.com/volatiletech/sqlboiler/v4 v4.1.1
go.uber.org/zap v1.15.0
golang.org/x/text v0.3.2
google.golang.org/api v0.23.0
google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587
google.golang.org/grpc v1.29.1
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
Loading