Code Monkey home page Code Monkey logo

pcbook-go's Introduction

PC Book - Go

This repository contains the Golang codes for an application to manage and search for laptop configurations using gRPC and golang.

The PC book application

PC book is an application to manage and search laptop configurations. It provides 4 gRPC APIs:

  1. Create a new laptop: [unary gRPC]

    This is a unary RPC API that allows client to create a new laptop with some specific configurations.

    The input of the API is a laptop, and it returns the unique ID of the created laptop.

    The laptop ID is a UUID, and can be set by the client, or randomly generated by the server if it's not provided.

  2. Search laptops with some filtering conditions: [server-streaming gRPC]

    This is a server-streaming RPC API that allows client to search for laptops that satisfies some filtering conditions, such as the maximum price, minimum cores, minimum CPU frequency, and minimum RAM.

    The input of the API is the filtering conditions, and it returns a stream of laptops that satisfy the conditions.

  3. Upload a laptop image file in chunks: [client-streaming gRPC]

    This is a client-streaming RPC API that allows client to upload 1 laptop image file to the server. The file will be split into multiple chunks of 1 KB, and they will be sent to the server as a stream.

    The input of the API is a stream of request, which can either be:

    • Metadata of the image (only the 1st request): which contains the laptop ID, and the image type (or file extension) such as .jpg or .png.
    • Or a binary data chunk of the image.

    The total size of the image should not exceed 1 MB.

    The API will returns a response that contains the uploaded image ID (random UUID generated by the server) and the total size of the image.

  4. Rate multiple laptops and get back average rating for each of them: [bidirectional-streaming gRPC]

    This is a bidirectional-streaming RPC API that allows client to rate multiple laptops, each with a score between 1 to 10, and get back the average rating score for each of them.

    The input of the API is a stream of requests, each with a laptop ID and a score.

    The API will returns a stream of responses, each contains a laptop ID, the number of times that laptop was rated, and the average rated score.

Major Features

  • Write and serialise protocol-buffer messages using Go.
  • Define gRPC services with protocol-buffer and generate Go codes.
  • Implement 4 types of gRPC using Go + Java: unary, server-streaming, client-streaming, bidirectional streaming.
  • Handle context deadline, gRPC errors and status codes.
  • Write production-grade application with interfaces and unit tests for gRPC services.
  • Use gRPC interceptors to authenticate & authorise users with JWT.
  • Secure gRPC connection with sever-side & mutual SSL/TLS.
  • Enable gRPC reflections for service discovery.

Setup development environment

  • Install protoc:
brew install protobuf
  • Install protoc-gen-go and protoc-gen-go-grpc
go get google.golang.org/protobuf/cmd/protoc-gen-go
go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
  • Install protoc-gen-grpc-gateway and protoc-gen-openapiv2
go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2

How to run

  • Generate codes from proto files:
make gen
  • Clean up generated codes in pb and swagger folders:
make clean
  • Run unit tests:
make test
  • Run server and client:
make server
make client
  • Generate SSL/TLS certificates:
make cert

pcbook-go's People

Contributors

hou-sz avatar

Watchers

 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.