web

package
v0.0.0-...-82ef66b Latest Latest
Warning

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

Go to latest
Published: May 28, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package web contains a small web framework for building services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTraceID

func GetTraceID(ctx context.Context) string

func IsShutdownError

func IsShutdownError(err error) bool

func NewShutdownError

func NewShutdownError(message string) error

func Respond

func Respond(ctx context.Context, w http.ResponseWriter, data any, statusCode int) error

func SetStatusCode

func SetStatusCode(ctx context.Context, statusCode int)

Types

type App

type App struct {
	*httptreemux.ContextMux
	// contains filtered or unexported fields
}

App is the entrypoint into our application and what configures our context.

func NewApp

func NewApp(shutdown chan os.Signal, mw ...Middleware) *App

NewApp constructs an App value to handle a set of routes for the application.

func (*App) Handle

func (a *App) Handle(method string, path string, handler Handler, mw ...Middleware)

Handle sets a handler function for a given HTTP method and path pair to the application server mux.

func (*App) SignalShutdown

func (a *App) SignalShutdown()

type Handler

type Handler func(ctx context.Context, w http.ResponseWriter, r *http.Request) error

type Middleware

type Middleware func(Handler) Handler

Middleware is a function that wraps a handler to perform pre/post processing.

type Values

type Values struct {
	TraceID    string
	Now        time.Time
	StatusCode int
}

func GetValues

func GetValues(ctx context.Context) *Values

GetValues returns the web values from the context. If the context does not contain vaues, it returns a meaningful default.

Jump to

Keyboard shortcuts

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