server

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package server provides types for running an HTTP server with middleware.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, config Config) error

Run an HTTP server based on the provided configuration. This function blocks until the provided context is cancelled.

Types

type Config

type Config struct {
	// The port to serve HTTP traffic on.
	Port int
	// Individual controllers to register onto the server's http.Handler.
	Controllers []Controller
	// Middleware functions to invoke prior to request handlers.
	Middleware []Middleware
	// Enables debug endpoints for pprof.
	Debug bool
}

The Config type contains configuration values used for running an HTTP server.

type Controller

type Controller interface {
	// Register the Controller's endpoints onto the provided http.ServeMux.
	Register(m *http.ServeMux)
}

The Controller interface describes types that register HTTP request handlers.

type Middleware

type Middleware func(http.Handler) http.Handler

The Middleware type is a function that wraps an http.Handler. Used to perform actions prior to handling requests.

Jump to

Keyboard shortcuts

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