server

package
v3.10.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2019 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRouter

func NewRouter(c Controller) *mux.Router

NewRouter returns a mux.Router with no middleware. This is so we can attach additional routes to the router if necessary

func PanicMiddleware

func PanicMiddleware(h http.Handler) http.Handler

PanicMiddleware logs any panics. For now, we're continue throwing the panic up the stack so this may crash the process.

func TracingMiddleware

func TracingMiddleware(h http.Handler) http.Handler

TracingMiddleware creates a new span named after the URL path of the request. It places this span in the request context, for use by other handlers via opentracing.SpanFromContext() If a span exists in request headers, the span created by this middleware will be a child of that span.

func WithTracingOpName

func WithTracingOpName(ctx context.Context, opName string) context.Context

WithTracingOpName adds the op name to a context for use by the tracing library. It uses a pointer because it's called below in the stack and the only way to pass the info up is to have it a set a pointer. Even though it doesn't change the context we still have this return a context to maintain the illusion.

Types

type Controller

type Controller interface {

	// GetSectionsForStudent handles GET requests to /students/{student_id}/sections
	// Gets the sections for the specified student
	// 200: []models.Section
	// 400: *models.BadRequest
	// 500: *models.InternalError
	// default: client side HTTP errors, for example: context.DeadlineExceeded.
	GetSectionsForStudent(ctx context.Context, studentID string) ([]models.Section, error)
}

Controller defines the interface for the blog service.

type Server

type Server struct {
	// Handler should generally not be changed. It exposed to make testing easier.
	Handler http.Handler
	// contains filtered or unexported fields
}

Server defines a HTTP server that implements the Controller interface.

func AttachMiddleware

func AttachMiddleware(router *mux.Router, addr string, m []func(http.Handler) http.Handler) *Server

AttachMiddleware attaches the given middleware to the router; this is to be used in conjunction with NewServer. It attaches custom middleware passed as arguments as well as the built-in middleware for logging, tracing, and handling panics. It should be noted that the built-in middleware executes first followed by the passed in middleware (in the order specified).

func New

func New(c Controller, addr string) *Server

New returns a Server that implements the Controller interface. It will start when "Serve" is called.

func NewWithMiddleware

func NewWithMiddleware(c Controller, addr string, m []func(http.Handler) http.Handler) *Server

NewWithMiddleware returns a Server that implemenets the Controller interface. It runs the middleware after the built-in middleware (e.g. logging), but before the controller methods. The middleware is executed in the order specified. The server will start when "Serve" is called.

func (*Server) Serve

func (s *Server) Serve() error

Serve starts the server. It will return if an error occurs.

Jump to

Keyboard shortcuts

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