gocloud.devgocloud.dev/server Index | Files | Directories

package server

import "gocloud.dev/server"

Package server provides a preconfigured HTTP server with diagnostic hooks.

Index

Variables

Set is a Wire provider set that produces a *Server given the fields of Options. This set might add new inputs over time, but they can always be the zero value.

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) 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

	// TraceExporter exports sampled trace spans.
	TraceExporter trace.Exporter

	// DefaultSamplingPolicy is a function that takes a
	// trace.SamplingParameters struct and returns a true or false decision about
	// whether it should be sampled and exported.
	DefaultSamplingPolicy trace.Sampler

	// Driver serves HTTP requests.
	Driver driver.Server
}

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(opts *Options) *Server

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

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe(addr string, h http.Handler) error

ListenAndServe is a wrapper to use wherever http.ListenAndServe is used. It wraps the passed-in http.Handler 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.

Source Files

server.go

Directories

PathSynopsis
server/driverPackage driver defines an interface for custom HTTP listeners.
server/sdserverPackage sdserver provides the diagnostic hooks for a server using Stackdriver.
server/xrayserverPackage xrayserver provides the diagnostic hooks for a server using AWS X-Ray.
Version
v0.9.0
Published
Jan 15, 2019
Platform
linux/amd64
Imports
10 packages
Last checked
1 day ago

Tools for package owners.