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 ContextWithSignals ¶ added in v0.21.0
ContextWithSignals creates a new instance of signal context.
Types ¶
type Halter ¶ added in v0.21.0
type Halter interface {
// Halt should tell the worker to stop doing work.
Halt(context.Context) error
}
Halter represents the behaviour for stopping a service worker.
type Runner ¶ added in v0.21.0
type Runner interface {
// Run should run start processing the worker and be a blocking operation.
Run(context.Context) error
}
Runner represents the behaviour for running a service worker.
type Service ¶
type Service struct {
// Name represents the name of the service, typically the same as the github repository.
Name string `json:"name"`
// Type represents the type of the service, eg. service or aggregator.
Type string `json:"type"`
// Version represents the latest version or SVC tag of the service.
Version string `json:"version"`
// Revision represents the SVC revision or commit hash of the service.
Revision string `json:"revision"`
// GracePeriod represents the duration workers have to clean up before the process gets killed.
GracePeriod time.Duration `json:"grace_period"`
}
Service represents the minimal information required to define a working service.
func NewService ¶
NewService creates a new service based on
Example ¶
package main
import (
"github.com/LUSHDigital/core"
)
func main() {
core.NewService("example", "service")
}
func (*Service) MustRun ¶ added in v0.21.0
MustRun will start the given service workers and block block indefinitely, until interupted. The process with an appropriate status code.
func (*Service) Run ¶ added in v0.21.0
Run will start the given service workers and block block indefinitely, until interupted.
func (*Service) StartWorkers ¶
StartWorkers will start the given service workers and block block indefinitely, until interupted. The process with an appropriate status code. DEPRECATED: Use MustRun in favour of StartWorkers.
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() {
service := core.NewService("example", "service")
service.MustRun(ctx,
grpcsrv.New(nil),
httpsrv.NewDefault(handler),
metricsrv.New(nil),
keybroker.NewRSA(nil),
)
}
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
|
|
|
service
command
|
|
|
Package i18n provides functions for dealing with internationalisation of services.
|
Package i18n provides functions for dealing with internationalisation of services. |
|
Package middleware is used to interact with HTTP & gRPC middlewares.
|
Package middleware is used to interact with HTTP & gRPC middlewares. |
|
i18nmw
Package i18nmw provides transport middlewares for dealing with internationalisation.
|
Package i18nmw provides transport middlewares for dealing with internationalisation. |
|
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 rest defines the how the default microservice response must look and behave like.
|
Package rest 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. |
|
Package workers is used to setup gracefully terminating workers for services.
|
Package workers is used to setup gracefully terminating workers for services. |
|
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. |
Core (Go)