Categorygithub.com/davetweetlive/learning_go_gRPC
repositorypackage
0.0.0-20211227020801-e7f50d318765
Repository: https://github.com/davetweetlive/learning_go_grpc.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

learning-go-gRPC

Notes

https://github.com/happilymarrieddad/learning-go-gRPC

Things to put in your bash

export PATH=$PATH:/usr/local/go/bin export PATH=$PATH:/home/comp/go/bin

Other things to install

Ubuntu

sudo apt install mysql-server

Snippets

{ "Omega Assertion": { "prefix": "omega", "body": "Ω($1)", "description": "Ginkgo Gomega Assertion" }, }

Section 1

  1. Intro
  2. Setup ENV

Section 2 -

  1. setup migrations
  2. Create User types
  3. Add validation

Section 3 - setup repos

  1. Create global repo
  2. Create users repo
  3. Add Create func
  4. Add FindById func
  5. Add FindByEmail func
  6. Add Update func
  7. Discuss testing and install gomega && ginkgo
    • ginkgo bootstrap
    • IF YOU WANT TO USE SQL-MOCK, please take a look at git branch section3-lesson10
  8. Add Create tests
    • ginkgo -v -failFast --focus="UsersRepo"
  9. Add FindById tests
  10. Add FindByEmail tests
  11. Add Update tests
  12. Generate mocks for repos

Section 4 - Protobuf

If you get the wrong version of protobuf use these commands

Make sure you grab the latest version

curl -OL https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-linux-x86_64.zip

Unzip

unzip protoc-3.2.0-linux-x86_64.zip -d protoc3

Move protoc to /usr/local/bin/

sudo mv protoc3/bin/* /usr/local/bin/

Move protoc3/include to /usr/local/include/

sudo mv protoc3/include/* /usr/local/include/

Optional: change owner

sudo chown $USER /usr/local/bin/protoc sudo chown -R $USER /usr/local/include/google

I did change the last step to:

ln -s /protoc3/bin/protoc /usr/bin/protoc

  1. Intro to protobufs
  2. Add types protobuf
  3. Add users protobuf
  4. Add auth protobuf
  5. Generate protobuf files

Section 5 - API

  1. Create utils file
  2. Create globalRepo intercepter
  3. Create users handler
  4. Flesh out users Create route
  5. Flesh out users FindById route
  6. Flesh out users FindByEmail route
  7. Flesh out users Update route
  8. Build initial users tests file
  9. Build Create tests
  10. Build FindById tests
  11. Build FindByEmail tests
  12. Build Update tests
  13. Run full test suite for users
  14. Create a main.go file to run the server

Section 6 - gRPC command line testing

  1. Install grpc_cli
  2. Run grpc_cli ls command to see all available services
  3. Run grpc_cli call command to create a user
    • grpc_cli call localhost:8080 users.V1Users.Create "newUser:{firstName:'Nick',lastName:'Doe2',email:'[email protected]',password:'1234',confirmPassword:'1234'}"

Section 7 - JWT

  1. Create Auth repo
  2. Add GetNewClaims func
  • go get -u github.com/pascaldekloe/jwt
  1. Add GetSignedToken func
  2. Add GetDataFromToken func
  3. Create tests file
  4. Build GetNewClaims tests
  5. Build GetSignedToken tests
  6. Build GetDataFromToken tests
  7. Run full test suite for auth
  8. Flesh out auth Login route
  9. Build initial auth tests file
  10. Build Login tests
  11. Run full test suite for auth
  12. Build api file to integrate routes
  13. Run grpc_cli call command to login with a user
    • grpc_cli call localhost:8080 auth.V1Auth.Login "email:'[email protected]', password: '1234'"
  14. Intro to gRPC authentication
  15. Add JWT field to routes
  16. Add JWT checks to the interceptor
    • grpc_cli call localhost:8080 auth.V1Auth.Login "email:'[email protected]', password: '1234'"
    • grpc_cli call localhost:8080 users.V1Users.Create "newUser:{firstName:'Nick2',lastName:'Doe2',email:'[email protected]',password:'1234',confirmPassword:'1234'}"
  17. Test routes

GRPC-WEB

https://github.com/grpc/grpc-web https://github.com/improbable-eng/grpc-web/tree/master/go/grpcwebproxy

install into our project

npm install grpc grpc-web google-protobuf --save