web

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrInternalServer     = errors.New("internal server error")
)

Functions

func NewHandler

func NewHandler(rp RequestProcessor, logf func(error)) http.HandlerFunc

func NewRequestProcessor

func NewRequestProcessor[I, O any](reqm RequestMapper[I], resm ResponseMapper[O], fn func(context.Context, I) (O, error)) *requestProcessor[I, O]

func ReadJSON

func ReadJSON(r *http.Request, dst any) error

func WriteJSON

func WriteJSON(w io.Writer, r Response) error

WriteJSON writes a JSON response to the io.Writer or http.ResponseWriter.

Types

type LoginInput

type LoginInput struct{ EmailAddress string }

type LoginOutput

type LoginOutput struct{ AccessToken string }

type LoginProcessor

type LoginProcessor struct {
	// contains filtered or unexported fields
}

func NewLoginProcessor

func NewLoginProcessor() *LoginProcessor

func (*LoginProcessor) Process

func (p *LoginProcessor) Process(ctx context.Context, input LoginInput) (LoginOutput, error)

type LoginRequestProcessor

type LoginRequestProcessor = requestProcessor[LoginInput, LoginOutput]

func NewLoginRequestProcessor

func NewLoginRequestProcessor() *LoginRequestProcessor

type RequestMapper

type RequestMapper[I any] interface{ MapRequest(*http.Request, *I) error }

type RequestMapperFunc

type RequestMapperFunc[I any] func(*http.Request, *I) error

func NewLoginRequestMapper

func NewLoginRequestMapper() RequestMapperFunc[LoginInput]

func (RequestMapperFunc[I]) MapRequest

func (f RequestMapperFunc[I]) MapRequest(r *http.Request, input *I) error

type RequestProcessor

type RequestProcessor interface{ ProcessRequest(*http.Request) Response }

type Response

type Response interface {
	Code() int
	Body() any
	Header() http.Header
}

type ResponseMapper

type ResponseMapper[O any] interface{ MapResponse(Result[O]) Response }

type ResponseMapperFunc

type ResponseMapperFunc[O any] func(Result[O]) Response

func NewLoginResponseMapper

func NewLoginResponseMapper() ResponseMapperFunc[LoginOutput]

func (ResponseMapperFunc[O]) MapResponse

func (f ResponseMapperFunc[O]) MapResponse(result Result[O]) Response

type Result

type Result[T any] interface{ Unwrap() (T, error) }

Directories

Path Synopsis
Package server provides a simple web server.
Package server provides a simple web server.

Jump to

Keyboard shortcuts

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