Coder Social home page Coder Social logo

learning-go-grpc's Introduction

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
    • git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
    • cd grpc
    • git submodule update --init
    • make grpc_cli
    • sudo make install grpc_cli
    • IF IT FAILS ON YOU DO THE FOLLOWING!!
      • I just found out a workaround. If you add -Wno-unused-variable to the cppflags at line 356 of Makefile at grpc root folder, the complier will ignore the unused variable warning/error.
      • grpc/grpc#16739
      • cp ./bins/opt/grpc_cli ~/go/bin
  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

learning-go-grpc's People

Contributors

happilymarrieddad avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.