web

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT 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

func GetTime

func GetTime(ctx context.Context) time.Time

GetTime returns the time from the context.

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.a

func Respond

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

Respond converts a Go value to JSON and sends it to the client.

func SetStatusCode

func SetStatusCode(ctx context.Context, statusCode int)

SetStatusCode sets the status code back into the context.

func SetValues

func SetValues(ctx context.Context, v *Values) context.Context

Types

type App

type App struct {
	*mux.Router
	// contains filtered or unexported fields
}

func NewApp

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

func (*App) Handle

func (a *App) Handle(path string, method 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 designed to run some code before and/or after another Handler. It is designed to remove boilerplate or other concerns not direct to any given Handler.

type Values

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

Values represent state for each request.

func GetValues

func GetValues(ctx context.Context) *Values

GetValues returns the values from the context.

Jump to

Keyboard shortcuts

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