brick

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 44 Imported by: 6

README ¶

🧱 brick

Build Status

Brick is a minimalistic opinionated web service unit suitable for microservice development.

Documentation ¶

Overview ¶

Package brick contains facades and configurations that are useful for a variety of apps.

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func MountDevPortal ¶

func MountDevPortal(r chi.Router, l *BaseLocator)

MountDevPortal mounts debug handlers to router.

func NewBaseRouter ¶

func NewBaseRouter(l *BaseLocator) chi.Router

NewBaseRouter initializes default http router.

func Start ¶

func Start(envPrefix string, cfg WithBaseConfig, init func(docsMode bool) (*BaseLocator, http.Handler))

Start loads config and runs application with provided service locator and http router.

Types ¶

type BaseConfig ¶

type BaseConfig struct {
	// Initialized indicates zero/uninitialized value of the configuration.
	Initialized bool `default:"true"`

	Log zapctxd.Config `split_words:"true"`

	// Environment is the name of environment where application runs.
	Environment string `default:"dev"`

	// ServiceName is the name of the service to use in documentation and tracing.
	ServiceName string `split_words:"true"`

	// HTTPListenAddr is the address of HTTP server listener.
	HTTPListenAddr string `split_words:"true" default:":80"`

	// ShutdownTimeout limits time for graceful shutdown of an application.
	ShutdownTimeout time.Duration `split_words:"true" default:"10s"`

	// Debug controls dev tools.
	Debug debug.Config `split_words:"true"`
}

BaseConfig is a basic application agnostic service configuration that manages common infrastructure.

func (*BaseConfig) Base ¶

func (c *BaseConfig) Base() BaseConfig

Base exposes base config.

type BaseLocator ¶

type BaseLocator struct {
	BaseConfig BaseConfig

	ctxd.LoggerProvider
	stats.TrackerProvider
	*graceful.Switch
	DebugRouter *debug.Mux

	UseCaseMiddlewares []usecase.Middleware

	HTTPRequestDecoder    *request.DecoderFactory
	HTTPServerMiddlewares []func(h http.Handler) http.Handler
	OpenAPI               *openapi.Collector

	Storage *sqluct.Storage
}

BaseLocator is a basic application agnostic service locator that manages common infrastructure.

func NewBaseLocator ¶

func NewBaseLocator(cfg BaseConfig) (*BaseLocator, error)

NewBaseLocator initializes basic service locator.

func NoOpLocator ¶

func NoOpLocator() *BaseLocator

NoOpLocator creates a dummy service locator, suitable to docs rendering.

func (*BaseLocator) SetupDebugRouter ¶

func (l *BaseLocator) SetupDebugRouter()

SetupDebugRouter initializes a router with debug tools.

func (*BaseLocator) StartHTTPServer ¶

func (l *BaseLocator) StartHTTPServer(handler http.Handler) (string, error)

StartHTTPServer starts HTTP server with provided handler in a goroutine and returns listening addr or error.

Server will listen at BaseConfig.HTTPListenAddr, if the value is empty free random port will be used.

Server will be gracefully stopped on service locator shutdown.

type WithBaseConfig ¶

type WithBaseConfig interface {
	Base() BaseConfig
}

WithBaseConfig is an embedded config accessor.

Directories ¶

Path Synopsis
Package config provides configuration loader based on env vars.
Package config provides configuration loader based on env vars.
Package database provides database instrumentation.
Package database provides database instrumentation.
Package debug provides debug helpers.
Package debug provides debug helpers.
zpages
Package zpages provides OpenCensus zpages handlers.
Package zpages provides OpenCensus zpages handlers.
Package graceful orchestrates shutdown gracefully.
Package graceful orchestrates shutdown gracefully.
Package jaeger configures OpenCensus Jaeger exporter.
Package jaeger configures OpenCensus Jaeger exporter.
Package log provides logging instrumentation.
Package log provides logging instrumentation.
Package opencensus provides helpers for OpenCensus instrumentation.
Package opencensus provides helpers for OpenCensus instrumentation.
Package runtime provides observability helpers.
Package runtime provides observability helpers.
Package test provides feature test runner.
Package test provides feature test runner.
Package usecase provides usecase instrumentation.
Package usecase provides usecase instrumentation.

Jump to

Keyboard shortcuts

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