webapp

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

README

webapp

Latest release Build status Go Report Card Documentation

Package webapp is an opinionated foundation for server based applications. It uses zerolog for logging, OpenTelemetry for collecting metrics and traces.

go get github.com/go-pogo/webapp
import "github.com/go-pogo/webapp"

Documentation

Additional detailed documentation is available at pkg.go.dev

Created with

License

Copyright © 2024-2026 Roel Schut. All rights reserved.

This project is governed by a BSD-style license that can be found in the LICENSE file.

Documentation

Index

Constants

View Source
const (
	ErrApplyOptions errors.Msg = "error while applying option(s)"
	ErrSetupServer  errors.Msg = "failed to setup server"
)
View Source
const (
	ErrDuringRun      errors.Msg = "an error occurred during run"
	ErrRunCanceled    errors.Msg = "run canceled"
	ErrDuringShutdown errors.Msg = "an error occurred during shutdown"
)
View Source
const (
	BuildInfoRoute   = buildinfo.MetricName
	HealthCheckRoute = "healthcheck"
	FaviconRoute     = "favicon"
)

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, targets ...func(ctx context.Context) error) error

func Shutdown

func Shutdown(ctx context.Context, targets ...func(ctx context.Context) error) error

Shutdown calls all targets and blocks until all are called and have returned. Returned errors from these functions are collected and returned at the end.

func ShutdownTimeout

func ShutdownTimeout(ctx context.Context, timeout time.Duration, targets ...func(ctx context.Context) error) error

ShutdownTimeout calls all targets and blocks until all are called and have returned, or when the timeout elapses. Returned errors from these functions are collected and returned at the end.

Types

type Base

type Base struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) (*Base, error)

func (*Base) BuildInfo added in v0.2.0

func (base *Base) BuildInfo() *buildinfo.BuildInfo

func (*Base) CheckHealth

func (base *Base) CheckHealth(_ context.Context) healthcheck.Status

func (*Base) HealthChecker

func (base *Base) HealthChecker() *healthcheck.Checker

func (*Base) RouteHandler

func (base *Base) RouteHandler() serv.RouteHandler

func (*Base) Run

func (base *Base) Run(ctx context.Context) error

func (*Base) Server

func (base *Base) Server() *serv.Server

func (*Base) Shutdown

func (base *Base) Shutdown(ctx context.Context) error

func (*Base) Telemetry

func (base *Base) Telemetry() *telemetry.Telemetry

type Option

type Option func(base *Base, config *config) error

func WithBuildInfo

func WithBuildInfo(bld *buildinfo.BuildInfo) Option

func WithHealthChecker

func WithHealthChecker(opts ...healthcheck.Option) Option

func WithIgnoreFaviconRoute

func WithIgnoreFaviconRoute() Option

func WithLogger

func WithLogger(log Logger) Option

func WithName added in v0.2.0

func WithName(name string) Option

func WithNotFoundHandler

func WithNotFoundHandler(h http.Handler) Option

func WithReadBuildInfo added in v0.2.0

func WithReadBuildInfo() Option

WithReadBuildInfo reads build info using buildinfo.Read. It also logs the read build when a logger implementing the logger.BuildInfoLogger interface is set using WithLogger.

func WithRoutesRegisterer

func WithRoutesRegisterer(rr serv.RoutesRegisterer) Option

func WithServerConfig

func WithServerConfig(conf ServerConfig) Option

func WithServerOption

func WithServerOption(opts ...serv.Option) Option

func WithTelemetryConfig

func WithTelemetryConfig(conf telemetry.Config) Option

type ServerConfig

type ServerConfig struct {
	// Port for the server to listen on.
	Port serv.Port `default:"8080"`
	// AccessLog enables logging of requests and their response code when true.
	AccessLog bool `default:"true"`
	TLS       easytls.Config
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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