go-fx-grpc-starter

module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2021 License: BSD-3-Clause

README

About

Boilerplate code to kickstart grpc projects with uber/fx and uber/zap logger

It can be run by providing an implementation of FxGrpcServerDefinition that registers the services

// main.go
func main() {
	fxapp.StartApp(
		fxgrpc.Module,
		fx.provide(NewServiceDefinitionProvider),
	)
}

By default GRPC server runs on localhost:9090, it can be overridden via environment variables APP_FX_GRPC_HOST and APP_FX_GRPC_PORT

Example project using the boiler can be found at https://github.com/srlk/go-fx-grpc-hello-world

Environment

Below environment variables are used by the started

Env Desc Default Examples
APP_FX_GRPC_HOST Host the GRPC server listens localhost localhost
APP_FX_GRPC_PORT TCP Port the GRPC server listens 9090 9090
APP_FX_GRPC_TLS_CERT Certificate content if HTTPS is preferred -----BEGIN CERTIFICATE-----\r\nMIIE....
APP_FX_GRPC_TLS_KEY Private key if HTTPS is preferred -----BEGIN PRIVATE KEY-----\r\nMII

Running via HTTPS

To run via HTTPS a certificate and private key should be generated.

To create a self signed certificate and private key

 openssl req -x509  \
  -sha256 -nodes -days 365  \
  -newkey rsa:2048  \
  -keyout private.key  \
  -out certificate.crt \

And then provide contents of certificate and private key as environment variable

export APP_FX_GRPC_TLS_CERT=$(awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}'  certificate.crt)

export APP_FX_GRPC_TLS_KEY=$(awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}'  private.key)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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