Documentation ¶
Index ¶
- func BadRequest400[T any](r *NexResponse, message string)
- func Conflict409[T any](r *NexResponse, message string)
- func Forbidden403[T any](r *NexResponse, message string)
- func InternalServerError500[T any](r *NexResponse, message string)
- func MethodNotAllowed405[T any](r *NexResponse, message string)
- func NoContent204[T any](r *NexResponse, message string)
- func NotFound404[T any](r *NexResponse, message string)
- func Ok200[T any](r *NexResponse, data T, message string)
- func Ok201[T any](r *NexResponse, data T, message string)
- func Ok202[T any](r *NexResponse, data T, message string)
- func Unauthorized401[T any](r *NexResponse, message string)
- type Body
- type Context
- func (c *Context) Error() error
- func (c *Context) Get(key string) any
- func (c *Context) GetHeader(key string) string
- func (c *Context) Set(key string, value any)
- func (c *Context) SetError(err error)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) String(status int, s string)
- func (c *Context) Validate(v interface{}) []nexval.ValidationError
- type Form
- func (f *Form) Bind(v interface{}) error
- func (f *Form) BindMultiPart(v interface{}) error
- func (f *Form) CheckCSRF() bool
- func (f *Form) Get(name string) string
- func (f *Form) GetAsBool(name string) (bool, error)
- func (f *Form) GetAsFloat64(name string) (float64, error)
- func (f *Form) GetAsInt(name string) (int, error)
- func (f *Form) GetAsInt64(name string) (int64, error)
- func (f *Form) GetFile(name string) (multipart.File, *multipart.FileHeader, error)
- func (f *Form) GetMultiple(name string) []string
- func (f *Form) HasField(name string) bool
- type NexResponse
- func (r *NexResponse) HTML(status int, payload string)
- func (r *NexResponse) JSON(status int, payload interface{})
- func (r *NexResponse) JsonBadRequest400(message string)
- func (r *NexResponse) JsonConflict409(message string)
- func (r *NexResponse) JsonForbidden403(message string)
- func (r *NexResponse) JsonInternalServerError500(message string)
- func (r *NexResponse) JsonMethodNotAllowed405(message string)
- func (r *NexResponse) JsonNoContent204(message string)
- func (r *NexResponse) JsonNotFound404(message string)
- func (r *NexResponse) JsonOk200(data any, message string)
- func (r *NexResponse) JsonOk201(data any, message string)
- func (r *NexResponse) JsonOk202(data any, message string)
- func (r *NexResponse) JsonUnauthorized401(message string)
- func (r *NexResponse) Text(status int, payload string)
- type PathParam
- type QueryParam
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequest400 ¶
func BadRequest400[T any](r *NexResponse, message string)
BadRequest400 - response with status 400 and data of any generic type The server could not understand the request due to invalid syntax. The client SHOULD NOT repeat the request without modifications.
func Conflict409 ¶
func Conflict409[T any](r *NexResponse, message string)
Conflict409 - response with status 409 and data of any generic type This response is sent when a request conflicts with the current state of the server.
func Forbidden403 ¶
func Forbidden403[T any](r *NexResponse, message string)
Forbidden403 - response with status 403 and data of any generic type The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401, the client's identity is known to the server.
func InternalServerError500 ¶
func InternalServerError500[T any](r *NexResponse, message string)
InternalServerError500 - response with status 500 and data of any generic type The server has encountered a situation it doesn't know how to handle.
func MethodNotAllowed405 ¶
func MethodNotAllowed405[T any](r *NexResponse, message string)
MethodNotAllowed405 - response with status 405 and data of any generic type The request method is known by the server but has been disabled and cannot be used. For example, an API may forbid DELETE-ing a resource. The two mandatory methods, GET and HEAD, must never be disabled and should not return this error code.
func NoContent204 ¶
func NoContent204[T any](r *NexResponse, message string)
NoContent204 - response with status 204 and data of any generic type There is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones.
func NotFound404 ¶
func NotFound404[T any](r *NexResponse, message string)
NotFound404 - response with status 404 and data of any generic type The server can not find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurrence on the web.
func Ok200 ¶
func Ok200[T any](r *NexResponse, data T, message string)
Ok200 - response with status 200 and data of any generic type The request succeeded. The result meaning of "success" depends on the HTTP method: GET: The resource has been fetched and transmitted in the message body. HEAD: The representation headers are included in the response without any message body. PUT or POST: The resource describing the result of the action is transmitted in the message body. TRACE: The message body contains the request message as received by the server.
func Ok201 ¶
func Ok201[T any](r *NexResponse, data T, message string)
Created201 - response with status 201 and data of any generic type The request succeeded, and a new resource was created as a result. This is typically the response sent after POST requests, or some PUT requests.
func Ok202 ¶
func Ok202[T any](r *NexResponse, data T, message string)
Accepted202 - response with status 202 and data of any generic type The request has been received but not yet acted upon. It is non-committal, meaning that there is no way in HTTP to later send an asynchronous response indicating the outcome of processing the request. It is intended for cases where another process or server handles the request, or for batch processing.
func Unauthorized401 ¶
func Unauthorized401[T any](r *NexResponse, message string)
Unauthorized401 - response with status 401 and data of any generic type Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
Types ¶
type Body ¶
type Body struct {
// contains filtered or unexported fields
}
type Context ¶
type Context struct { Request *http.Request Response http.ResponseWriter Params map[string]string // for route parameters Res *NexResponse PathParam *PathParam QueryParam *QueryParam Form *Form Body *Body Data map[string]any // contains filtered or unexported fields }
Context is the main structure that will be passed to handlers. It provides methods and fields to interact with the HTTP request and response.
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request) *Context
NewContext creates a new instance of Context.
func (*Context) Validate ¶
func (c *Context) Validate(v interface{}) []nexval.ValidationError
Validate - validates a struct.with the Go Playground validator v10 package struct tags.
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
func (*Form) BindMultiPart ¶
BindMultiPart - binds the multipart form to the given struct.
func (*Form) CheckCSRF ¶
CheckCSRF - Checks if CSRF token is valid. This assumes you're adding a CSRF token in your forms.
func (*Form) GetAsFloat64 ¶
GetAsFloat64 - returns the value of the form parameter with the given name as a float64.
func (*Form) GetMultiple ¶
GetMultiple - Returns multiple values for a given key (useful for checkboxes, multi-selects).
type NexResponse ¶
type NexResponse struct {
// contains filtered or unexported fields
}
func NewNexResponse ¶
func NewNexResponse(ctx *Context) *NexResponse
NexResponse - create new NexResponse
func (*NexResponse) HTML ¶
func (r *NexResponse) HTML(status int, payload string)
HTML sends a html response with the given status code and payload.
func (*NexResponse) JSON ¶
func (r *NexResponse) JSON(status int, payload interface{})
JSON sends a JSON response with the given status code and payload.
func (*NexResponse) JsonBadRequest400 ¶
func (r *NexResponse) JsonBadRequest400(message string)
BadRequest400 - response with status 400 The server could not understand the request due to invalid syntax. The client SHOULD NOT repeat the request without modifications.
func (*NexResponse) JsonConflict409 ¶
func (r *NexResponse) JsonConflict409(message string)
Conflict409 - response with status 409 This response is sent when a request conflicts with the current state of the server.
func (*NexResponse) JsonForbidden403 ¶
func (r *NexResponse) JsonForbidden403(message string)
Forbidden403 - response with status 403 The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401, the client's identity is known to the server.
func (*NexResponse) JsonInternalServerError500 ¶
func (r *NexResponse) JsonInternalServerError500(message string)
InternalServerError500 - response with status 500 The server has encountered a situation it doesn't know how to handle.
func (*NexResponse) JsonMethodNotAllowed405 ¶
func (r *NexResponse) JsonMethodNotAllowed405(message string)
MethodNotAllowed405 - response with status 405 The request method is known by the server but has been disabled and cannot be used. For example, an API may forbid DELETE-ing a resource. The two mandatory methods, GET and HEAD, must never be disabled and should not return this error code.
func (*NexResponse) JsonNoContent204 ¶
func (r *NexResponse) JsonNoContent204(message string)
NoContent204 - response with status 204 There is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones.
func (*NexResponse) JsonNotFound404 ¶
func (r *NexResponse) JsonNotFound404(message string)
NotFound404 - response with status 404 The server can not find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurrence on the web.
func (*NexResponse) JsonOk200 ¶
func (r *NexResponse) JsonOk200(data any, message string)
JsonOk200 - response with status 200 The request succeeded. The result meaning of "success" depends on the HTTP method: GET: The resource has been fetched and transmitted in the message body. HEAD: The representation headers are included in the response without any message body. PUT or POST: The resource describing the result of the action is transmitted in the message body. TRACE: The message body contains the request message as received by the server.
func (*NexResponse) JsonOk201 ¶
func (r *NexResponse) JsonOk201(data any, message string)
Created201 - response with status 201 The request succeeded, and a new resource was created as a result. This is typically the response sent after POST requests, or some PUT requests.
func (*NexResponse) JsonOk202 ¶
func (r *NexResponse) JsonOk202(data any, message string)
Accepted202 - response with status 202 The request has been received but not yet acted upon. It is non-committal, meaning that there is no way in HTTP to later send an asynchronous response indicating the outcome of processing the request. It is intended for cases where another process or server handles the request, or for batch processing.
func (*NexResponse) JsonUnauthorized401 ¶
func (r *NexResponse) JsonUnauthorized401(message string)
Unauthorized401 - response with status 401 Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
func (*NexResponse) Text ¶
func (r *NexResponse) Text(status int, payload string)
Text sends a plain text response with the given status code and payload.
type PathParam ¶
type PathParam struct {
// contains filtered or unexported fields
}
func NewPathParam ¶
type QueryParam ¶
type QueryParam struct {
// contains filtered or unexported fields
}
func NewQueryParam ¶
func NewQueryParam(ctx *Context) *QueryParam
NewQueryParam creates a new instance of QueryParam.
func (*QueryParam) Get ¶
func (q *QueryParam) Get(name string) string
Get returns the value of the query parameter with the given name.
func (*QueryParam) GetAsBool ¶
func (q *QueryParam) GetAsBool(name string) (bool, error)
Boolean method
func (*QueryParam) GetAsInt ¶
func (q *QueryParam) GetAsInt(name string) (int, error)
Integer related methods
func (*QueryParam) GetAsInt64 ¶
func (q *QueryParam) GetAsInt64(name string) (int64, error)