go-grpc-server-template

command module
v0.0.0-...-8c995eb Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

README

Go gRPC Server Template

What is this?

This is a starter template to kick off a repo holding a gRPC server written in golang.

It includes

  1. A top level main that listens for SIGINT and SIGTERM and gracefully closes its database connection and the gRPC server
  2. Has a simple embedded data store badger
  3. Has a starting point for configuration with a interface wrapper around viper
  4. Has a github workflow
  5. Has a dev container
  6. Has a Dockerfile
  7. Has a Makefile for common tasks such as building, testing, linting
  8. Is automatically updated with renovate renovate.json

How do I change the .proto and update the associated code?

You can run make generate-grpc-code in the dev container and it will re-generate the golang code under api/v1 to match what's specified in the .proto file.

What configuration properties are available?

Configuration Property Default Value Description
database.path data/db Path to the database file
server.port 50051 Port on which the server listens
server.address localhost Address on which the server listens
server.tls.enabled false Enable TLS for the server
server.tls.cert "" TLS certificate content
server.tls.cert_path "" Path to the TLS certificate file
server.tls.key "" TLS key content
server.tls.key_path "" Path to the TLS key file
server.tls.ca "" CA certificate content
server.tls.ca_path "" Path to the CA certificate file
How to set configuration values

You can set these configuration properties using either environment variables or a YAML configuration file. Viper is used to extract the configuration properties.

Using Environment Variables

Set the environment variables with the corresponding configuration property names in uppercase and replace dots with underscores. For example:

export DATABASE_PATH="custom/db/path"
export SERVER_PORT="8080"
export SERVER_ADDRESS="0.0.0.0"
export SERVER_TLS_ENABLED="true"
export SERVER_TLS_CERT="your_cert_content"
export SERVER_TLS_CERT_PATH="/path/to/cert"
export SERVER_TLS_KEY="your_key_content"
export SERVER_TLS_KEY_PATH="/path/to/key"
export SERVER_TLS_CA="your_ca_content"
export SERVER_TLS_CA_PATH="/path/to/ca"
Using a config file

Create a config file in the same directory that the process runs in.

Below is an example

database:
  path: "custom/db/path"

server:
  port: 8080
  address: "0.0.0.0"
  tls:
    enabled: true
    cert: "your_cert_content"
    cert_path: "/path/to/cert"
    key: "your_key_content"
    key_path: "/path/to/key"
    ca: "your_ca_content"
    ca_path: "/path/to/ca"
Certs/Keys

server.tls.cert and the matching fields without the _path suffix, are expected to be string values in PEM format. These will be used first, if they are empty, then the associated path variable is used, the expectation is the file provided in the path property is also PEM formatted.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
v1
repositories
services

Jump to

Keyboard shortcuts

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