server

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package server provides an http server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Response

func Response(ctx context.Context, w http.ResponseWriter, err error)

Response writes an http error responses to the http.ResponseWriter.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option provides options for configuring the creation of a http server.

func WithAddr

func WithAddr(addr string) Option

WithAddr will configure the server with the listen address.

func WithCORS

func WithCORS(c *cors.Options) Option

WithCORS will configure the server with the CORS options.

func WithReadTimeout added in v0.0.15

func WithReadTimeout(timeout time.Duration) Option

WithReadTimeout sets the http server read timeout.

func WithShutdownTimeout

func WithShutdownTimeout(timeout time.Duration) Option

WithShutdownTimeout sets the timout for shutting down the server.

func WithTLS

func WithTLS(cfg *tls.Config) Option

WithTLS will configure the server to require TLS.

func WithWriteTimeout added in v0.0.15

func WithWriteTimeout(timeout time.Duration) Option

WithWriteTimeout sets the http server read timeout.

type ResponseError

type ResponseError struct {
	// Status is the http status code applicable to this problem.
	Status int `json:"status"`

	// Detail is a human-readable explanation specific to this occurrence of
	// the problem.
	Detail string `json:"detail,omitempty"`
}

ResponseError provides additional information about problems encounted while performing an operation. See: https://jsonapi.org/format/#error-objects

swagger:response ResponseError

func (ResponseError) Error

func (e ResponseError) Error() string

Error translates the error to a string.

type Server

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

Server represents an HTTP server.

func New

func New(ctx context.Context, opts ...Option) *Server

New creates an HTTP server with and has not started to accept requests yet.

func (*Server) Middleware

func (s *Server) Middleware(mw ...mux.MiddlewareFunc)

Middleware installs the given middleware with the router.

func (*Server) Register

func (s *Server) Register(ctx context.Context, services ...Service)

Register associates the given services with the router.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve accepts incoming connections. This is a blocking call and should be called in the context of a new goroutime.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown stops the http server gracefully without interrupting any active connections. It will, however, forcefully stop if the shutdown timeout expires while shutting down.

type Service

type Service interface {
	// Register will register this service with the given router.
	Register(router *mux.Router)

	// Name provides the name of the service.
	Name() string

	// Shutdown allows the service to stop any long running background processes it
	// may have.
	Shutdown(context.Context)
}

Service defines the methods required by the Server to register with the service with the router.

Jump to

Keyboard shortcuts

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