Categorygithub.com/LUSHDigital/core
modulepackage
0.24.0
Repository: https://github.com/lushdigital/core.git
Documentation: pkg.go.dev

# README

License Go Report Card Build Status Documentation

Donguri by Cerys Evans Core (Go)

A collection of packages for building a Go microservice on the LUSH platform.

Quick start

Below there's an example for how to get running quickly with a service using the LUSHDigital core package.

package main

import (
	"context"
	"net/http"
	"time"

	"github.com/LUSHDigital/core"
	"github.com/LUSHDigital/core/middleware/metricsmw"
	"github.com/LUSHDigital/core/workers/httpsrv"
	"github.com/LUSHDigital/core/workers/keybroker"
	"github.com/LUSHDigital/core/workers/metricsrv"
	"github.com/LUSHDigital/core/workers/readysrv"
)

var service = &core.Service{
	Name:    "example",
	Type:    "service",
	Version: "1.0.0",
}

func main() {
	metrics := metricsrv.New(nil)
	broker := keybroker.NewPublicRSA(nil)
	readiness := readysrv.New(nil, readysrv.Checks{
		"public_rsa_key": broker,
	})

	handler := metricsmw.MeasureRequests(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
		w.WriteHeader(200)
		w.Write([]byte("hello world"))
	}))

	server := httpsrv.New(&http.Server{
		ReadTimeout: 10 * time.Second,
		Handler:     handler,
	})

	service.MustRun(context.Background(),
		server,
		metrics,
		broker,
		readiness,
	)
}

Documentation

Documentation and examples are provided in README files in each package.

Core Concepts

These packages contain functionality for the core concepts of our services.

Middlewares

These packages contain convenient middlewares for transport protocols like HTTP REST and gRPC.

Workers

These packages contain convenient workers things like network servers, background workers and message brokers.

Plugins

There are a few libraries that can be used in conjunction with the core library containing their own service workers, ready checks and/or middlewares.

Tools

There are a few tools that can be used with projects that use the core library.

Recommended Libraries

Some libraries have been designed to work together with the core library and some are even dependencies. Consider using these if you need extended functionality for certain things.

  • LUSHDigital/scan: Scan database/sql rows directly to a struct, slice, or primitive any type. Originally forked from github.com/blockloop/scan
  • LUSHDigital/uuid: A UUID package originally forked from github.com/gofrs/uuid & github.com/satori/go.uuid
  • LUSHDigital/spew: A pretty-printer package originally forked from github.com/davecgh/go-spew/spew

Contributors

# Packages

Package auth provides functions for services to issue and sign api consumer tokens.
Package env provides functionality for ensuring we retrieve an environment variable.
No description provided by the author
Package i18n provides functions for dealing with internationalisation of services.
Package middleware is used to interact with HTTP & gRPC middlewares.
Package pagination defines a paginator able to return formatted responses enabling the API consumer to retrieve data in defined chunks.
Package rest defines the how the default microservice response must look and behave like.
Package test contains helpers for aiding testing.
Package workers is used to setup gracefully terminating workers for services.

# Functions

ContextWithSignals creates a new instance of signal context.
NewService creates a new service based on.
SetupLogs will set up the appropriate log flags.
WaitWithTimeout will wait for a number of pieces of work has finished and send a message on the completed channel.

# Structs

Service represents the minimal information required to define a working service.

# Interfaces

Halter represents the behaviour for stopping a service worker.
Runner represents the behaviour for running a service worker.
Worker represents the behaviour for a service worker.