Documentation ¶
Index ¶
- Constants
- Variables
- func Delete[I Body, O Body](fn HandleFunc[I, O], options ...Options) http.HandlerFunc
- func Get[I EmptyBody, O any](fn HandleFunc[I, O], options ...Options) http.HandlerFunc
- func Patch[I Body, O Body](fn HandleFunc[I, O], options ...Options) http.HandlerFunc
- func Post[I Body, O Body](fn HandleFunc[I, O], options ...Options) http.HandlerFunc
- func Put[I Body, O Body](fn HandleFunc[I, O], options ...Options) http.HandlerFunc
- type Body
- type EmptyBody
- type HandleFunc
- type MarshalFunc
- type Options
- type Request
- func (req *Request[T]) Body() *T
- func (req *Request[T]) Context() context.Context
- func (req *Request[T]) Cookie(name string) (*http.Cookie, error)
- func (req *Request[T]) Cookies() []*http.Cookie
- func (req *Request[T]) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (req *Request[T]) FormValue(key string) string
- func (req *Request[T]) HTTPRequest() *http.Request
- func (req *Request[T]) Header() http.Header
- func (req *Request[T]) MultipartReader() (*multipart.Reader, error)
- func (req *Request[T]) ParseForm() error
- func (req *Request[T]) ParseMultipartForm(maxMemory int64) error
- func (req *Request[T]) PostFormValue(key string) string
- func (req *Request[T]) ProtoAtLeast(major, minor int) bool
- func (req *Request[T]) Referer() string
- func (req *Request[T]) URL() *url.URL
- func (req *Request[T]) UserAgent() string
- func (req *Request[T]) Value(key any) any
- type Response
Constants ¶
const ( // ContentType header constant. ContentType = "Content-Type" Accept = "Accept" // ContentJSON header value for JSON data. ContentJSON = "application/json" // ContentProto header value for proto buff ContentProto = "application/proto" // TODO :: Add additional content type support // ContentBinary header value for binary data. ContentBinary = "application/octet-stream" // ContentHTML header value for HTML data. ContentHTML = "text/html" // ContentText header value for Text data. ContentText = "text/plain" // ContentXHTML header value for XHTML data. ContentXHTML = "application/xhtml+xml" // ContentXML header value for XML data. ContentXML = "text/xml" )
Variables ¶
Functions ¶
func Delete ¶
func Delete[I Body, O Body](fn HandleFunc[I, O], options ...Options) http.HandlerFunc
Delete deletes the specified resource. The underlying request body is optional.
func Get ¶
func Get[I EmptyBody, O any](fn HandleFunc[I, O], options ...Options) http.HandlerFunc
Get requests a representation of the specified resource. Expects an empty request body. If a request body is set, it will be ignored.
func Patch ¶
func Patch[I Body, O Body](fn HandleFunc[I, O], options ...Options) http.HandlerFunc
Patch method is used to apply partial modifications to a resource. Required Request Body
func Post ¶
func Post[I Body, O Body](fn HandleFunc[I, O], options ...Options) http.HandlerFunc
Post method can be used in two different ways, create a resource or perform and operation:. Optional request body
func Put ¶
func Put[I Body, O Body](fn HandleFunc[I, O], options ...Options) http.HandlerFunc
Put method is used to replace a resource with a similar resource that includes a different set of values. Requires request body
Types ¶
type HandleFunc ¶
HandleFunc responds to an HTTP request. I and O represent the request body or response body.
type MarshalFunc ¶ added in v0.0.3
MarshalFunc defines how a body should be marshaled into bytes
type Options ¶
type Options interface {
Apply(*opts)
}
func WithDefaultContentType ¶ added in v0.0.3
Defines the Default Content-type to be used if one is not set by the user.
func WithVerbose ¶ added in v0.0.3
type Request ¶
type Request[T Body] struct { // contains filtered or unexported fields }
A Request represents an HTTP request received by a server
func (*Request[T]) Body ¶
func (req *Request[T]) Body() *T
Body returns the generic http body, or nil if no body exists.
func (*Request[T]) Cookie ¶
Cookie warps the underlying request's cookie and returns the named cookie provided in the request or ErrNoCookie if not found. If multiple cookies match the given name, only one cookie will be returned.
func (*Request[T]) Cookies ¶
Cookies wraps the underlying request and returns the HTTP cookies sent with the request.
func (*Request[T]) FormFile ¶
FormFile wraps the underlying request and returns the first file for the provided form key. FormFile calls ParseMultipartForm and ParseForm if necessary.
func (*Request[T]) FormValue ¶
FormValue wraps the underlying request and returns the first value for the named component of the query. POST and PUT body parameters take precedence over URL query string values. FormValue calls ParseMultipartForm and ParseForm if necessary and ignores any errors returned by these functions. If key is not present, FormValue returns the empty string. To access multiple values of the same key, call ParseForm and then inspect Request.Form directly.
func (*Request[T]) HTTPRequest ¶
HTTPRequest returns the raw HTTP Request. If the request contains a body, it will be nil and only available through the glhf request.Body() method. This method is a temporary function and will be deprecated in future releases.
func (*Request[T]) MultipartReader ¶
MultipartReader wraps the underlying request and returns a MIME multipart reader if this is a multipart/form-data or a multipart/mixed POST request, else returns nil and an error. Use this function instead of ParseMultipartForm to process the request body as a stream.
func (*Request[T]) ParseForm ¶
ParseForm wraps the underlying request and populates r.Form and r.PostForm.
func (*Request[T]) ParseMultipartForm ¶
ParseMultipartForm wraps the underlying request and parses a request body as multipart/form-data. The whole request body is parsed and up to a total of maxMemory bytes of its file parts are stored in memory, with the remainder stored on disk in temporary files. ParseMultipartForm calls ParseForm if necessary. If ParseForm returns an error, ParseMultipartForm returns it but also continues parsing the request body. After one call to ParseMultipartForm, subsequent calls have no effect.
func (*Request[T]) PostFormValue ¶
PostFormValue wraps the underlying request and returns the first value for the named component of the POST, PATCH, or PUT request body. URL query parameters are ignored. PostFormValue calls ParseMultipartForm and ParseForm if necessary and ignores any errors returned by these functions. If key is not present, PostFormValue returns the empty string.
func (*Request[T]) ProtoAtLeast ¶
ProtoAtLeast wraps the underlying request and reports whether the HTTP protocol used in the request is at least major.minor.
func (*Request[T]) Referer ¶
Referer wraps the underlying request and returns the referring URL, if sent in the request.
type Response ¶
type Response[T any] struct { // contains filtered or unexported fields }
Response represents the response from an HTTP request.
func (*Response[T]) AddHeader ¶ added in v0.0.2
Add adds the key, value pair to the header. It appends to any existing values associated with key. The key is case insensitive; it is canonicalized by CanonicalHeaderKey.
func (*Response[T]) SetBody ¶ added in v0.0.2
func (res *Response[T]) SetBody(t *T)
SetBody sets the response body
func (*Response[T]) SetHeader ¶ added in v0.0.2
SetHeader sets the header entries associated with key to the single element value. It replaces any existing values associated with key. The key is case insensitive. It is canonicalized by textproto.CanonicalMIMEHeaderKey. To use non-canonical keys, assign to the map directly.
func (*Response[T]) SetMarshalFunc ¶ added in v0.0.3
func (res *Response[T]) SetMarshalFunc(fn MarshalFunc[T])
SetMarshalFunc sets the response marshal func. If a marshal function is supplied, it is prioritized over other implemented marshaler regardless of the content-type or accept headers set.