web

package
v0.0.0-...-cd28de7 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r *http.Request, val any) error

Decode reads the body of an HTTP request looking for a JSON document. The body is decoded into the provided value. If the provided value is a struct then it is checked for validation tags. If the value implements a validate function, it is executed.

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID returns the trace id from the context.

func IsShutdown

func IsShutdown(err error) bool

IsShutdown checks to see if the shutdown error is contained in the specified error value.

func NewShutdownError

func NewShutdownError(message string) error

NewShutdownError returns an error that causes the framework to signal a graceful shutdown.

func Param

func Param(r *http.Request, key string) string

Param returns the web call parameters from the request.

func Respond

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

Respond sends a response to the client.

Types

type App

type App struct {
	*http.ServeMux
	// contains filtered or unexported fields
}

App is the entrypoint into our application and what configures our context object for each of our http handlers. Feel free to add any configuration data/logic on this App struct.

func NewApp

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

func (*App) HandleFunc

func (a *App) HandleFunc(pattern string, handler Handler, mw ...MidHandler)

func (*App) HandleFuncNoMiddleware

func (a *App) HandleFuncNoMiddleware(pattern string, handler Handler, mw ...MidHandler)

HandleFuncNoMiddleware sets a handler function for a given HTTP method and path pair to the application server mux with no middleware.

func (*App) SignalShutdown

func (a *App) SignalShutdown()

SignalShutdown is used to gracefully shut down the app when an integrity issue is identified.

type Handler

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

Handler HandlerFunc represents a function that handles a http request within our own little mini framework.

type MidHandler

type MidHandler func(handler Handler) Handler

MidHandler is a handler function designed to run code before and/or after another Handler. It is designed to remove boilerplate or other concerns not direct to any given app Handler.

type NoResponse

type NoResponse struct{}

NoResponse tells the Respond function to not respond to the request. In these cases the app layer code has already done so.

func NewNoResponse

func NewNoResponse() NoResponse

NewNoResponse constructs a no reponse value.

func (NoResponse) Encode

func (NoResponse) Encode() ([]byte, string, error)

Encode implements the Encoder interface

type Values

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

func GetValues

func GetValues(ctx context.Context) *Values

Jump to

Keyboard shortcuts

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