This repo has been created during doing this gRPC course on Udemy.
The greet
and blog
app I did together with the instructor.
The calculator
app I did mostly on my own. (Of course at the end I checked the solution and fixed mine if it was needed).
In Section 9 - Advanced features
there are errors, deadlines/timeouts, SSL and reflection that I did along with the instructor and affected calculator
as well as greet
.
After the course I added:
- Example interceptor to the
greet
server () - Example tests to the
greet
app - Bit of extra information about how to use Evans CLI / grpcURL with (m)TLS
- Instead of using
--go_opt=modules=github.com/Akos-T/grpc-go-course
I'm using--go_opt=paths=source_relative
. Same for--go-grpc_opt
. - Instead of using a
makefile
, I'm usingBuf CLI
andgo generate
.
- Install Buf if you don't have it yet
- If you use
homebrew
, runbrew install bufbuild/buf/buf
- If you don't use
homebrew
, please see here how to install Buf
- If you use
- Install protoc for Go
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
- Run
export PATH="$PATH:$(go env GOPATH)/bin"
- To make this permanent, you should add this to your terminal profile, e.g.:
.zshrc
and restrart the terminal or runsource ~/.zshrc
- To make this permanent, you should add this to your terminal profile, e.g.:
- Details can be found here
- Alternatively, the Buf config can be changed to use remote plugins in which case you don't have to install protoc locally. See the docs here.
- This is only needed for greet: In the ssl folder, run
ssl.sh
to generate your self-signed certificates for TLS in greet - Navigate to the project folder (greet or calculator)
- Run
go generate
- Start the server:
- In case of greet:
./bin/greet/server
- In case of calculator:
./bin/server
- In case of greet:
- Start the client:
- In case of greet:
./bin/greet/client
- In case of calculator:
./bin/client
- In case of greet:
- Navigate to the blog folder
- Run
go generate
- Run
docker compose up
- In another terminal navigate to the blog folder and run
./bin/server
- In another terminal navigate to the blog folder and run
./bin/client
- Navigate to the greet folder
- Run
go test ./server
- Run the server (for steps, see the
How to build the apps
section above) - Install Evans CLI if haven't already: https://github.com/ktr0731/evans?tab=readme-ov-file#installation
- Run
evans --tls --host localhost -p 5051 --cacert "../ssl/ca.crt" -r repl
- Use Evans REPL however you want to. E.g.:
show package package <<package name>> show service service <<service name>> call <<RPC name>>
Documentation: https://github.com/ktr0731/evans?tab=readme-ov-file#usage-repl
Alternatively it is possible to use grpcURL
, for example:
# With mTLS
grpcurl -cacert "../ssl/ca.crt" -d '{"first_name":"Maynard"}' localhost:5051 greet.GreetService.Greet
# With TLS, but we don't check the server's certificate (no mTLS)
grpcurl -insecure -d '{"first_name":"Maynard"}' localhost:5051 greet.GreetService.Greet
# Without TLS - If TLS is turned on in the server, this will timeout
grpcurl -plaintext -d '{"first_name":"Maynard"}' localhost:5051 greet.GreetService.Greet
Response in each case:
{
"result": "Hello Maynard"
}