kweb

package
v0.0.0-...-7213d9b Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDev = errors.New("fatal error")

Functions

func NewHandler

func NewHandler(handleStruct Handler) func(http.ResponseWriter, *http.Request)

NewHandler allocates a new handle and executes each method from the Handler interface

Types

type Error

type Error struct {
	Status  int    `json:"-"`
	Message string `json:"error,omitempty"`
	Err     error  `json:"-"`
	Kind    string `json:"-"`
}

func DecodeHTTPTags

func DecodeHTTPTags(req *http.Request, t reflect.Type, v reflect.Value) *Error

func ErrorWrap

func ErrorWrap(err error) *Error

func ErrorWrapMsg

func ErrorWrapMsg(err error, msg string) *Error

func (Error) Error

func (e Error) Error() string

type Fetcher

type Fetcher struct{}

func (*Fetcher) Fetch

func (handle *Fetcher) Fetch(r *http.Request) *Error

type Handle

type Handle struct {
	Fetcher
	Reader
	Writer
}

type Handler

type Handler interface {
	// Read the request Headers, Params, Body into handleStruct
	Read(r *http.Request, handleStruct Handler) *Error
	// Fetch whatever is needed from the http request to put into the Handler (headers, query params, ..)
	Fetch(r *http.Request) *Error
	// Do executes the api call operational code without access to the writer or the request and returns
	// the response as a struct, or an error
	Do(ctx context.Context) (any, *Error)
	// Write format the response output
	Write(w http.ResponseWriter, r *http.Request, resp any)
}

type Reader

type Reader struct{}

func (*Reader) Read

func (handle *Reader) Read(r *http.Request, handleStruct Handler) *Error

type ReaderJSON

type ReaderJSON struct {
	Reader
}

ReaderJSON overrides the Read method of Handler, it takes the json body from the Request and read it into the handle herited structure.

func (ReaderJSON) Read

func (handle ReaderJSON) Read(r *http.Request, handleStruct Handler) *Error

type Response

type Response struct {
	Status int
	Body   any
}

Response

type Writer

type Writer struct {
	WriteFn func(w http.ResponseWriter, code int, obj any)
}

Writer

func (*Writer) Write

func (handle *Writer) Write(w http.ResponseWriter, r *http.Request, resp any)

func (*Writer) WriteFnJSON

func (handle *Writer) WriteFnJSON(w http.ResponseWriter, code int, obj any)

func (*Writer) WriteText

func (handle *Writer) WriteText(w http.ResponseWriter, code int, obj any)

type WriterJSON

type WriterJSON struct {
	Writer
}

func (*WriterJSON) Write

func (handle *WriterJSON) Write(w http.ResponseWriter, r *http.Request, response any)

Jump to

Keyboard shortcuts

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