Giter Club home page Giter Club logo

grpc-sample's Introduction

GRPC sample service

alt text

Server

This is ticket review score calculator that masquerades as GRPC sample service :) Weights are used to amplify ratings by category:

weighted rating = (rating * weight) + rating

0-100 score gets calculated:

score = ((rating * weight) + rating)/((maxRating * weight) + maxRating) * 100

Reguired for building the project locally:

Run service locally:

# Download dependencis
go mod download
# Generate protobuf file
./protoc-code.sh
# Optionally also vendor dependencies
go mod vendor -mod=readonly
# run the service
go run cmd/server/main.go

Supported service flags:

  -db-file="database.db": Path to SQLite file path
  -db-host="localhost": PostgreSQL address
  -db-name="": PostgreSQL database name
  -db-password="": PostgreSQL password
  -db-port=5432: PostgreSQL port
  -db-user="": PostgreSQL user
  -docs-path="./pb": Documentation html and proto definition directory
  -grpc-port=8080: Service port to listen for GRPC requests
  -http-port=8081: Service port to listen for HTTP requests

All the flags can also be passed in as environment variables.

If -db-user, -db-password and db-name it will try to connect to PostgreSQL. Otherwise it will attempt to open SQLite database file. By default it uses the SQLite database found in the repository. There is also migrate-to-psql.sh to migrate data to a local PostgreSQL database.

Health check works with grpc-health-probe:

./grpc_health_probe -addr=:8080

In addition to GRPC methods the following HTTP methods are served:

  • /metrics Prometheus metrics endpoint
  • /docs Proto service documentation page
  • /proto Service proto file

Also available in Docker Hub:

docker pull tanelmae/grpc-sample

CLI client

Simple CLI client is found in cmd/client/main.go.

Supported subcommands and flags:

category-scores
  -from string
    	Start time for the period (default "2019-03-01")
  -to string
    	End time for the period (default "2019-04-01")

ticket-scores
  -from string
    	Start time for the period (default "2019-03-01")
  -to string
    	End time for the period (default "2019-04-01")

overal-score
  -from string
    	Start time for the period (default "2019-03-01")
  -out string
    	Format for the command output (default "silent")

period-diff
  -from string
    	Start time for the period (default "2019-03-01")
  -to string
    	End time for the period (default "2019-04-01")
  -second-from string
    	Start time for the period (default "2019-04-01")
  -second-to string
    	End time for the period (default "2019-04-30")

Shared flags for all commands
  -out string
    	Format for the command output (default "json")
      Also available: "table" and "silent"
  -addr string: Server address (default "localhost:8080")

Example:

batman@gotham:grpc-sample $ go run cmd/client/main.go period-diff -out table
+------------+--------+
|  CATEGORY  | CHANGE |
+------------+--------+
| Spelling   | 2 %    |
| Grammar    | 2 %    |
| GDPR       | -1 %   |
| Randomness | 0 %    |
+------------+--------+

grpc-sample's People

Contributors

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