server

package
v1.17.0 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: 18 Imported by: 13

Documentation

Overview

Package server provides an opinionated http server.

Package server provides an opinionated http server.

Although exported, this package is non intended for general consumption. It is a shared dependency between multiple exposure notifications projects. We cannot guarantee that there won't be breaking changes in the future.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleHealthz added in v0.6.0

func HandleHealthz(db *database.DB) http.Handler

Types

type MetricsDoneFunc added in v1.13.0

type MetricsDoneFunc func() error

func ServeMetricsIfPrometheus

func ServeMetricsIfPrometheus(ctx context.Context) (MetricsDoneFunc, error)

ServeMetricsIfPrometheus serves the opencensus metrics at /metrics when OBSERVABILITY_EXPORTER set to "prometheus".

type Server

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

Server provides a gracefully-stoppable http server implementation. It is safe for concurrent use in goroutines.

func New

func New(port string) (*Server, error)

New creates a new server listening on the provided address that responds to the http.Handler. It starts the listener, but does not start the server. If an empty port is given, the server randomly chooses one.

func NewFromListener added in v0.15.0

func NewFromListener(listener net.Listener) (*Server, error)

NewFromListener creates a new server on the given listener. This is useful if you want to customize the listener type (e.g. udp or tcp) or bind network more than `New` allows.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the server's listening address (ip + port).

func (*Server) IP

func (s *Server) IP() string

IP returns the server's listening IP.

func (*Server) Port

func (s *Server) Port() string

Port returns the server's listening port.

func (*Server) ServeGRPC

func (s *Server) ServeGRPC(ctx context.Context, srv *grpc.Server) error

ServeGRPC starts the server and blocks until the provided context is closed. When the provided context is closed, the server is gracefully stopped with a timeout of 5 seconds.

Once a server has been stopped, it is NOT safe for reuse.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(ctx context.Context, srv *http.Server) error

ServeHTTP starts the server and blocks until the provided context is closed. When the provided context is closed, the server is gracefully stopped with a timeout of 5 seconds.

Once a server has been stopped, it is NOT safe for reuse.

func (*Server) ServeHTTPHandler

func (s *Server) ServeHTTPHandler(ctx context.Context, handler http.Handler) error

ServeHTTPHandler is a convenience wrapper around ServeHTTP. It creates an HTTP server using the provided handler, wrapped in OpenCensus for observability.

Jump to

Keyboard shortcuts

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