server

package
v0.0.0-...-eb33cdb Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 12 Imported by: 5

Documentation

Overview

Package server provides a preconfigured HTTP server with diagnostic hooks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultDriver

type DefaultDriver struct {
	Server http.Server
}

DefaultDriver implements the driver.Server interface. The zero value is a valid http.Server.

func NewDefaultDriver

func NewDefaultDriver() *DefaultDriver

NewDefaultDriver creates a driver with an http.Server with default timeouts.

func (*DefaultDriver) ListenAndServe

func (dd *DefaultDriver) ListenAndServe(addr string, h http.Handler) error

ListenAndServe sets the address and handler on DefaultDriver's http.Server, then calls ListenAndServe on it.

func (*DefaultDriver) ListenAndServeTLS

func (dd *DefaultDriver) ListenAndServeTLS(addr, certFile, keyFile string, h http.Handler) error

ListenAndServeTLS sets the address and handler on DefaultDriver's http.Server, then calls ListenAndServeTLS on it.

DefaultDriver.Server.TLSConfig may be set to configure additional TLS settings.

func (*DefaultDriver) Shutdown

func (dd *DefaultDriver) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server without interrupting any active connections, by calling Shutdown on DefaultDriver's http.Server

type Options

type Options struct {
	// RequestLogger specifies the logger that will be used to log requests.
	RequestLogger requestlog.Logger

	// HealthChecks specifies the health checks to be run when the
	// /healthz/readiness endpoint is requested.
	HealthChecks []health.Checker

	// Driver serves HTTP requests.
	Driver driver.Server

	// PanicHandler specifies http.Handler that will be called when panic occured.
	// If nil, then default PanicHandler will be used.
	PanicHandler http.Handler

	// Logger specifies logger to use by Server when specific events occurs.
	Logger log.Logger
}

Options is the set of optional parameters.

type Server

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

Server is a preconfigured HTTP server with diagnostic hooks. The zero value is a server with the default options.

func New

func New(h http.Handler, opts *Options) *Server

New creates a new server. New(nil, nil) is the same as new(Server).

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe(addr string) error

ListenAndServe is a wrapper to use wherever http.ListenAndServe is used. It wraps the http.Handler provided to New with a handler that handles tracing and request logging. If the handler is nil, then http.DefaultServeMux will be used. A configured Requestlogger will log all requests except HealthChecks.

func (*Server) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS(addr, certFile, keyFile string) error

ListenAndServeTLS is a wrapper to use wherever http.ListenAndServeTLS is used. It wraps the http.Handler provided to New with a handler that handles tracing and request logging. If the handler is nil, then http.DefaultServeMux will be used. A configured Requestlogger will log all requests except HealthChecks.

func (*Server) Shutdown

func (srv *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server without interrupting any active connections.

Directories

Path Synopsis
Package driver defines an interface for custom HTTP listeners.
Package driver defines an interface for custom HTTP listeners.
Package health provides health check handlers.
Package health provides health check handlers.
sqlhealth
Package sqlhealth provides a health check for a SQL database connection.
Package sqlhealth provides a health check for a SQL database connection.
Package requestlog provides an http.Handler that logs information about requests.
Package requestlog provides an http.Handler that logs information about requests.
This package provides an http middleware to automatically log error from ResponseWriter.Write.
This package provides an http middleware to automatically log error from ResponseWriter.Write.

Jump to

Keyboard shortcuts

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