go-service

module
v1.60.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: Unlicense

README

CircleCI Coverage Status

Go Service

A framework to build services in go. This came out of out building services over the years and what I have considered good practices in building services. Hence it is highly subjective and opinionated.

This framework stands on the shoulder of giants so we don't reinvent the wheel!

Dependency Injection

This framework heavily relies on DI. We have chosen to use Uber FX. So there is great information online to get you up to speed.

Commands

A service has commands that are configured using Cobra. Each service has the following commands (you can add more):

  • Server - This will host your API.
  • Worker - This will host your background processing.
  • Client - This will have a command that starts and finishes.

These are configured in the main function.

Configuration

The configuration is based on YAML and is read from an env variable called CONFIG_FILE. The reason for this is that we want to be able to separate how configuration is retrieved. This way we can use and application configuration system.

The configuration can be watched for write changes. If it changes the application is stopped. This way an orchestration system can just restart the process.

This is the configuration.

Caching

The framework currently supports the following caching solutions:

We also support the following compressions to optimize cache size:

Health

The health package is based on go-health. This package allows us to create all sorts of ways to check external and internal systems.

We also provide ways to integrate into container integration systems. So we provide the following endpoints:

  • /health - This allows us to check any external dependency and provide a breakdown of what is not functioning. This should only be used for verification.
  • /liveness: Can be used for k8s liveness.
  • /readiness: Can be used for k8s readiness.

Logging

For logging we use Uber Zap.

Metrics

For metrics we use Prometheus.

Security

For security we support the following:

SQL

For SQL databases we support the following:

Tracing

For distributed tracing we support the following:

Transport

The transport layer provides ways to abstract communication for in/out of the service. So we have the following integrations:

REST

Below is list of the provided handlers:

Development

This section describes how to run and contribute to the project, if you are interested.

Style

We favour what is defined in the Uber Go Style Guide.

Setup

To get yourself setup, please run:

make setup
Environment

As we rely on external services these need to be configured:

Starting

Please run:

make start
Stopping

Please run:

make stop
Testing

To be able to test locally, please run:

make specs

Projects

Below is a list of projects using this framework:

Jump to

Keyboard shortcuts

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