Giter VIP home page Giter VIP logo

grpc-go-example's Introduction

Golang + gRPC

Golang + gRPC

Overview

This application implements a gRPC server with two services and a client to handle with requests, it also has a Server Streaming implementation.

  • gRPC Secure connection with SSL/TLS
  • gRPC Server
  • gRPC Server streaming
  • gRPC Service
  • gRPC Client
  • gRPC .proto
  • Evans Client gRPC
  • HTTP Server
  • Docker + Docker Compose

Setup

Clone repository

$ git clone https://github.com/Sup3r-Us3r/grpc-go-example
$ cd grpc-go-example

Access app

The environment were configured using Docker Compose, to start the environment you must run:

$ docker-compose up -d

Access the application container:

$ docker exec -it go-grpc-app /bin/bash

Install dependencies

$ go mod tidy

Configure certificate

First for you configure gRPC connection with SSL/TLS you need to edit this generate.sh file, and change the following information:

/C=BR is for country

/ST=Minas Gerais is for state or province

/L=Belo Horizonte is for locality name or city

/O=Example is for organisation

/OU=Education is for organisation unit

/CN=*.test is for common name or domain name

/emailAddress=[email protected] is for email address

Now run this command to generate the certificate, but it is important that you have openssl installed, if you run this command inside the container the image already has openssl installed:

$ make cert

Run server

$ go run main.go

Use gRPC client

For each created service you can use the client that was implemented to perform the request:

$ go run grpc/client/main.go

As this is just an example, when executing the above command the request will be made to the three existing services, you can comment on any that you do not want to be executed in your tests in grpc/client/main.go in the function main.

Use the Evans gRPC client

Open a new terminal and access the container app again, and run this command:

gRPC without security

$ evans -r repl

There is only 2 RPC in the ProductService and 1 RPC in the SmartwatchService.

To use RPC CreateProduct run:

[email protected]:50051> call CreateProduct

To use RPC ListProducts run:

[email protected]:50051> call ListProducts

To use RPC BeatsPerMinute run:

[email protected]:50051> call BeatsPerMinute

evans-grpc-client

Protobuf

For the .proto files that are used to define the contract, in case you want to modify something, or need to create new files, it is necessary to use protoc to generate the .pb and grpc.pb files.

Use the command below in the root of the project that uses protoc internally:

$ make gen

grpc-go-example's People

Contributors

sup3r-us3r avatar

Stargazers

 avatar

Watchers

 avatar  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.