Skip to content

Commit fe57cbf

Browse files
authored
Merge branch 'master' into tls-patch
2 parents 40a0588 + 75cf9a7 commit fe57cbf

Some content is hidden

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

58 files changed

+1194
-488
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
jobs:
1212
check_format:
13-
runs-on: ubuntu-20.04
13+
runs-on: ubuntu-latest
1414
name: Check format
1515
steps:
1616
- uses: actions/checkout@v3
@@ -29,15 +29,13 @@ jobs:
2929
- name: Check format
3030
run: mix format --check-formatted
3131
tests:
32-
runs-on: ubuntu-20.04
32+
runs-on: ubuntu-latest
3333
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
3434
strategy:
3535
matrix:
3636
otp: [24.x, 25.x, 26.1.x]
3737
elixir: [1.15.x]
38-
include:
39-
- otp: 24.x
40-
elixir: 1.12.x
38+
4139
needs: check_format
4240
steps:
4341
- uses: actions/checkout@v3
@@ -56,7 +54,7 @@ jobs:
5654
- name: Run Tests
5755
run: mix test
5856
interop-tests:
59-
runs-on: ubuntu-20.04
57+
runs-on: ubuntu-latest
6058
name: Interop tests
6159
needs: check_format
6260
if: ${{ github.ref != 'refs/heads/master' }}
@@ -80,17 +78,15 @@ jobs:
8078
working-directory: ./interop
8179

8280
interop-tests-all:
83-
runs-on: ubuntu-20.04
81+
runs-on: ubuntu-latest
8482
name: Interop tests OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
8583
needs: check_format
8684
if: ${{ github.ref == 'refs/heads/master' }}
8785
strategy:
8886
matrix:
8987
otp: [24.x, 25.x, 26.1.x]
9088
elixir: [1.15.x]
91-
include:
92-
- otp: 24.x
93-
elixir: 1.12.x
89+
9490
steps:
9591
- uses: actions/checkout@v3
9692
- uses: erlef/setup-beam@v1
@@ -111,7 +107,7 @@ jobs:
111107
working-directory: ./interop
112108

113109
check_release:
114-
runs-on: ubuntu-20.04
110+
runs-on: ubuntu-latest
115111
name: Check release
116112
needs: check_format
117113
steps:

README.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ An Elixir implementation of [gRPC](http://www.grpc.io/).
1515
- [Usage](#usage)
1616
- [Simple RPC](#simple-rpc)
1717
- [HTTP Transcoding](#http-transcoding)
18+
- [CORS](#cors)
1819
- [Start Application](#start-application)
1920
- [Features](#features)
2021
- [Benchmark](#benchmark)
@@ -24,13 +25,13 @@ An Elixir implementation of [gRPC](http://www.grpc.io/).
2425

2526
The package can be installed as:
2627

27-
```elixir
28-
def deps do
29-
[
30-
{:grpc, "~> 0.9"}
31-
]
32-
end
33-
```
28+
```elixir
29+
def deps do
30+
[
31+
{:grpc, "~> 0.10"}
32+
]
33+
end
34+
```
3435

3536
## Usage
3637

@@ -59,10 +60,10 @@ service Greeter {
5960
6061
```
6162

62-
2. Then generate Elixir code from proto file as [protobuf-elixir](https://github.com/tony612/protobuf-elixir#usage) shows (especially the `gRPC Support` section) or using [protobuf_generate](https://hex.pm/packages/protobuf_generate) hex package. Example using `protobuf_generate` lib:
63+
2. Then generate Elixir code from proto file as [protobuf-elixir](https://github.com/elixir-protobuf/protobuf#usage):
6364

6465
```shell
65-
mix protobuf.generate --output-path=./lib --include-path=./priv/protos helloworld.proto
66+
protoc --elixir_out=plugins=grpc:./lib -I./priv/protos helloworld.proto
6667
```
6768

6869
In the following sections you will see how to implement gRPC server logic.
@@ -96,7 +97,7 @@ end
9697

9798
We will use this module [in the gRPC server startup section](#start-application).
9899

99-
**__Note:__** For other types of RPC call like streams see [here](interop/lib/interop/server.ex).
100+
**Note:** For other types of RPC call like streams see [here](interop/lib/interop/server.ex).
100101

101102
### **HTTP Transcoding**
102103

@@ -152,6 +153,7 @@ mix protobuf.generate \
152153
```
153154

154155
3. Enable http_transcode option in your Server module
156+
155157
```elixir
156158
defmodule Helloworld.Greeter.Server do
157159
use GRPC.Server,
@@ -167,6 +169,23 @@ end
167169

168170
See full application code in [helloworld_transcoding](examples/helloworld_transcoding) example.
169171

172+
### **CORS**
173+
174+
When accessing gRPC from a browser via HTTP transcoding or gRPC-Web, CORS headers may be required for the browser to allow access to the gRPC endpoint. Adding CORS headers can be done by using `GRPC.Server.Interceptors.CORS` as an interceptor in your `GRPC.Endpoint` module, configuring it as decribed in the module documentation:
175+
176+
Example:
177+
178+
```elixir
179+
# Define your endpoint
180+
defmodule Helloworld.Endpoint do
181+
use GRPC.Endpoint
182+
183+
intercept GRPC.Server.Interceptors.Logger
184+
intercept GRPC.Server.Interceptors.CORS, allow_origin: "mydomain.io"
185+
run Helloworld.Greeter.Server
186+
end
187+
```
188+
170189
### **Start Application**
171190

172191
1. Start gRPC Server in your supervisor tree or Application module:
@@ -231,7 +250,7 @@ The accepted options for configuration are the ones listed on [Mint.HTTP.connect
231250
- [HTTP Transcoding](https://cloud.google.com/endpoints/docs/grpc/transcoding)
232251
- [TLS Authentication](https://grpc.io/docs/guides/auth/#supported-auth-mechanisms)
233252
- [Error handling](https://grpc.io/docs/guides/error/)
234-
- Interceptors (See [`GRPC.Endpoint`](https://github.com/elixir-grpc/grpc/blob/master/lib/grpc/endpoint.ex))
253+
- [Interceptors](`GRPC.Endpoint`)
235254
- [Connection Backoff](https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md)
236255
- Data compression
237256
- [gRPC Reflection](https://github.com/elixir-grpc/grpc-reflection)

benchmark/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Benchmark implementation followed by [official spec](https://grpc.io/docs/guides
55
## Usage
66

77
```
8-
$ git clone https://github.com/tony612/grpc.git
8+
$ git clone https://github.com/elixir-grpc/grpc.git
99
$ cd grpc && git checkout -t origin/elixir-bench
1010
$ git submodule update --init
1111
$ export ELIXIR_GRPC_PATH= # elixir-grpc path
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
defmodule Grpc.Core.Bucket do
22
@moduledoc false
3-
use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3
3+
4+
use Protobuf, protoc_gen_elixir_version: "0.14.1", syntax: :proto3
45

56
field :start, 1, type: :double
67
field :count, 2, type: :uint64
78
end
89

910
defmodule Grpc.Core.Histogram do
1011
@moduledoc false
11-
use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3
12+
13+
use Protobuf, protoc_gen_elixir_version: "0.14.1", syntax: :proto3
1214

1315
field :buckets, 1, repeated: true, type: Grpc.Core.Bucket
1416
end
1517

1618
defmodule Grpc.Core.Metric do
1719
@moduledoc false
18-
use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3
20+
21+
use Protobuf, protoc_gen_elixir_version: "0.14.1", syntax: :proto3
1922

2023
oneof :value, 0
2124

@@ -26,7 +29,8 @@ end
2629

2730
defmodule Grpc.Core.Stats do
2831
@moduledoc false
29-
use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3
32+
33+
use Protobuf, protoc_gen_elixir_version: "0.14.1", syntax: :proto3
3034

3135
field :metrics, 1, repeated: true, type: Grpc.Core.Metric
32-
end
36+
end
Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1 @@
1-
defmodule Grpc.Testing.BenchmarkService.Service do
2-
@moduledoc false
3-
use GRPC.Service, name: "grpc.testing.BenchmarkService", protoc_gen_elixir_version: "0.11.0"
41

5-
rpc :UnaryCall, Grpc.Testing.SimpleRequest, Grpc.Testing.SimpleResponse
6-
7-
rpc :StreamingCall, stream(Grpc.Testing.SimpleRequest), stream(Grpc.Testing.SimpleResponse)
8-
9-
rpc :StreamingFromClient, stream(Grpc.Testing.SimpleRequest), Grpc.Testing.SimpleResponse
10-
11-
rpc :StreamingFromServer, Grpc.Testing.SimpleRequest, stream(Grpc.Testing.SimpleResponse)
12-
13-
rpc :StreamingBothWays, stream(Grpc.Testing.SimpleRequest), stream(Grpc.Testing.SimpleResponse)
14-
end
15-
16-
defmodule Grpc.Testing.BenchmarkService.Stub do
17-
@moduledoc false
18-
use GRPC.Stub, service: Grpc.Testing.BenchmarkService.Service
19-
end

0 commit comments

Comments
 (0)