core

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

License Go Report Card Build Status GoDoc

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/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() {
	core.SetupLogs()

	metrics := metricsrv.New()
	broker := keybroker.NewRSA(nil)
	readiness := readysrv.New(readysrv.Checks{
		"rsa_key": broker,
	})

	server := httpsrv.New(&http.Server{
		ReadTimeout: 10 * time.Second,
		Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
			w.WriteHeader(200)
			w.Write([]byte("hello world"))
		}),
	})

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

Documentation

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

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.

Service Workers

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

Documentation

Overview

Package core consists of a set of packages which are used in writing micro-service applications.

Each package defines conventional ways of handling common tasks, as well as a suite of tests to verify their behaviour.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupLogs

func SetupLogs()

SetupLogs will set up the appropriate log flags.

Types

type Service

type Service struct {
	// Name represents the name of the service, typically the same as the github repository.
	Name string `json:"service_name"`
	// Type represents the type of the service, eg. service or aggregator.
	Type string `json:"service_type"`
	// Version represents the SVC tagged version of the service.
	Version string `json:"service_version"`
}

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

func NewService

func NewService() *Service

NewService reads a service definition from the environment.

Example
package main

import (
	"github.com/LUSHDigital/core"
)

func main() {
	core.NewService()
}
Output:

func (*Service) StartWorkers

func (s *Service) StartWorkers(ctx context.Context, workers ...ServiceWorker)

StartWorkers will start the given service workers and block block indefinitely.

Example
package main

import (
	"context"
	"net/http"

	"github.com/LUSHDigital/core"
	"github.com/LUSHDigital/core/workers/grpcsrv"
	"github.com/LUSHDigital/core/workers/httpsrv"
	"github.com/LUSHDigital/core/workers/keybroker"
	"github.com/LUSHDigital/core/workers/metricsrv"
)

var (
	ctx     context.Context
	handler http.Handler
)

func main() {
	svc := core.NewService()
	svc.StartWorkers(ctx,
		grpcsrv.New(nil),
		httpsrv.NewDefault(handler),
		metricsrv.New(),
		keybroker.NewRSA(nil),
	)
}
Output:

type ServiceWorker

type ServiceWorker interface {
	// Run should be a blocking operation
	Run(context.Context, io.Writer) error
}

ServiceWorker represents the behaviour for running a service worker.

Directories

Path Synopsis
Package auth provides functions for services to issue and sign api consumer tokens.
Package auth provides functions for services to issue and sign api consumer tokens.
Package env provides functionality for ensuring we retrieve an environment variable
Package env provides functionality for ensuring we retrieve an environment variable
examples
middleware
metricsmw
Package metricsmw is used to record and expose metrics for an application.
Package metricsmw is used to record and expose metrics for an application.
paginationmw
Package paginationmw provides transport middlewares for dealing with pagination.
Package paginationmw provides transport middlewares for dealing with pagination.
tracingmw
Package tracingmw allows setting and tracing a request by injecting an id as part of it's headers, when dealing with HTTP, or it's context, when dealing with GRPC.
Package tracingmw allows setting and tracing a request by injecting an id as part of it's headers, when dealing with HTTP, or it's context, when dealing with GRPC.
Package pagination defines a paginator able to return formatted responses enabling the API consumer to retrieve data in defined chunks
Package pagination defines a paginator able to return formatted responses enabling the API consumer to retrieve data in defined chunks
Package response defines the how the default microservice response must look and behave like.
Package response defines the how the default microservice response must look and behave like.
Package test contains helpers for aiding testing.
Package test contains helpers for aiding testing.
workers
grpcsrv
Package grpcsrv provides a default set of configuration for hosting a grpc server in a service.
Package grpcsrv provides a default set of configuration for hosting a grpc server in a service.
httpsrv
Package httpsrv provides a default set of configuration for hosting a http server in a service.
Package httpsrv provides a default set of configuration for hosting a http server in a service.
keybroker
Package keybroker implements a background broker conmtinous retrieval of public keys from multiple different type of sources.
Package keybroker implements a background broker conmtinous retrieval of public keys from multiple different type of sources.
keybroker/keybrokermock
Package keybrokermock implements no-op mocks for the keys package
Package keybrokermock implements no-op mocks for the keys package
metricsrv
Package metricsrv provides a default set of configuration for hosting http prometheus metrics in a service.
Package metricsrv provides a default set of configuration for hosting http prometheus metrics in a service.
readysrv
Package readysrv is used to provide readiness checks for a service.
Package readysrv is used to provide readiness checks for a service.

Jump to

Keyboard shortcuts

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