grpc-go-cnode

module
v0.0.0-...-b9535b4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2023 License: MIT

README

grpc-go-cnode

Go Report Card GitHub

A Go gRPC server for CNode community built on the top of RESTful API.

This project is just for teaching, NOT production ready.

After modifying the .proto files, need to re-compile protocol buffers. It will generate the service interfaces, models for the server side and service interfaces for client side. Then, you can implement the interfaces of the services.

Features:

  • HTTPs server and gRPC server share same listening address and port
  • Print access logs in unary call interceptor
  • gRPC Health check for entire server based on GRPC Health Checking Protocol
  • Per RPC call authentication, check auth.go
  • TLS connection with self-signed credentials
  • Support constraint rules and validators for Protocol buffer, check here
  • Server reflection, check GRPC Server Reflection Protocol
  • Integration and unit testings
  • Distributed trace with z-pages and stackdriver exporter

Compile protocol buffers:

make compile-protobuf

Don't support read environment variables from OS. Only support read environment variables from configs/config.yaml:

BASE_URL: https://cnodejs.org/api/v1
PORT: 3000
ACCESS_TOKEN: <YOUR_ACCESS_TOKEN>
GRPC_GO_LOG_SEVERITY_LEVEL: info
GRPC_GO_LOG_VERBOSITY_LEVEL: 1
GOOGLE_CLOUD_PROJECT: <YOUR_GCP_PROJECT_ID>
TRACE_ADMIN_CREDENTIAL_FILE: <YOUR_TRACE_SERVICE_ACCOUNT_JSON_FILE_PATH>

Start the HTTPs server and gRPC server:

make start

Run integration testings:

  1. Run make start to start the server
  2. Run make test-integration

Run unit testings:

make test-unit

List all gRPC services using grpcurl, using -insecure flag to skip server certificate and domain verification.

☁  grpc-go-cnode [master] grpcurl -insecure localhost:3000 list
grpc.health.v1.Health
grpc.reflection.v1alpha.ServerReflection
topic.TopicService
user.UserService

Or using -cacert flag to use a file containing trusted root certificates for verifying the server.

☁  grpc-go-cnode [master] grpcurl -cacert=./assets/server.crt localhost:3000 list
grpc.health.v1.Health
grpc.reflection.v1alpha.ServerReflection
topic.TopicService
user.UserService

You will see traces and stats exported on the stdout. You can also see the z-pages provided from the server:

E.g. Server side gRPC server traces from z-pages:

z-pages trace

Server side gPRC server trace from stackdriver trace:

stackdriver trace

More info, see Makefile

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL