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 ErrorWrapMsg ¶
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 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.
type Writer ¶
type Writer struct {
WriteFn func(w http.ResponseWriter, code int, obj any)
}
Writer
func (*Writer) WriteFnJSON ¶
func (handle *Writer) WriteFnJSON(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)
Click to show internal directories.
Click to hide internal directories.