web

package
v0.0.0-...-25a7e32 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r *http.Request, v Decoder) error

Decode reads the body of an HTTP request and decodes the body into the specified data model. If the data model implements the validator interface, the method will be called.

func GetWriter

func GetWriter(ctx context.Context) http.ResponseWriter

GetWriter returns the underlying writer for the request.

func Param

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

func Respond

func Respond(ctx context.Context, w http.ResponseWriter, dataModel Encoder) error

Respond sends a response to the client.

Types

type App

type App struct {
	// 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(log Logger, tracer trace.Tracer, mw ...MidFunc) *App

NewApp creates an App value that handle a set of routes for the application.

func (*App) EnableCORS

func (a *App) EnableCORS(origins []string)

func (*App) FileServer

func (a *App) FileServer(static embed.FS, dir string, path string) error

FileServer starts a file server based on the specified file system and directory inside that file system.

func (*App) FileServerReact

func (a *App) FileServerReact(static embed.FS, dir string, path string) error

FileServerReact starts a file server based on the specified file system and directory inside that file system for a statically built react webapp.

func (*App) HandlerFunc

func (a *App) HandlerFunc(method string, group string, path string, handlerFunc HandlerFunc, mw ...MidFunc)

func (*App) HandlerFuncNoMid

func (a *App) HandlerFuncNoMid(method string, group string, path string, handlerFunc HandlerFunc)

func (*App) RawHandlerFunc

func (a *App) RawHandlerFunc(method string, group string, path string, rawHandlerFunc http.HandlerFunc, mw ...MidFunc)

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

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Decoder

type Decoder interface {
	Decode(data []byte) error
}

Decoder represents data that can be decoded.

type Encoder

type Encoder interface {
	Encode() (data []byte, contentType string, err error)
}

Encoder defines behavior that can encode a data model and provide the content type for that encoding.

type HandlerFunc

type HandlerFunc func(ctx context.Context, r *http.Request) Encoder

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

type Logger

type Logger func(ctx context.Context, msg string, args ...any)

Logger represents a function that will be called to add information to the logs.

type MidFunc

type MidFunc func(handler HandlerFunc) HandlerFunc

type NoResponse

type NoResponse struct{}

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

Jump to

Keyboard shortcuts

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