Skip to content

My personal learning repo for Udemy course: gRPC [Golang] Master Class: Build Modern API & Microservices

Notifications You must be signed in to change notification settings

Akos-T/grpc-go-course

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gRPC [Golang] Master Class: Build Modern API & Microservices | Udemy

Overview

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:

Changes compared to the course

  • 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 using Buf CLI and go generate.

Prerequisites

  • Install Buf if you don't have it yet
    • If you use homebrew, run brew install bufbuild/buf/buf
    • If you don't use homebrew, please see here how to install Buf
  • 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 run source ~/.zshrc
    • 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.

How to build the apps (greet / calculator)

  1. This is only needed for greet: In the ssl folder, run ssl.sh to generate your self-signed certificates for TLS in greet
  2. Navigate to the project folder (greet or calculator)
  3. Run go generate
  4. Start the server:
    1. In case of greet: ./bin/greet/server
    2. In case of calculator: ./bin/server
  5. Start the client:
    1. In case of greet: ./bin/greet/client
    2. In case of calculator: ./bin/client

How to build the blog app

  1. Navigate to the blog folder
  2. Run go generate
  3. Run docker compose up
  4. In another terminal navigate to the blog folder and run ./bin/server
  5. In another terminal navigate to the blog folder and run ./bin/client

How to run the greet tests

  1. Navigate to the greet folder
  2. Run go test ./server

How to run Evans CLI/REPL or grpcURL with (m)TLS (Greet app)

  1. Run the server (for steps, see the How to build the apps section above)
  2. Install Evans CLI if haven't already: https://github.com/ktr0731/evans?tab=readme-ov-file#installation
  3. Run evans --tls --host localhost -p 5051 --cacert "../ssl/ca.crt" -r repl
  4. 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"
}

Certification - 2023-10-22

Useful links

About

My personal learning repo for Udemy course: gRPC [Golang] Master Class: Build Modern API & Microservices

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published