Documentation ¶
Overview ¶
Package framework is a minimal web framework.
Index ¶
- func Decode(r *http.Request, val any) error
- func GetParam(c *gin.Context, param string) *string
- func GetQueryValue(c *gin.Context, param string) *string
- func IsShutdown(err error) bool
- func LoggingRespondErrMsg(c *gin.Context, errMsg string, statusCode int)
- func LoggingRespondErrWithMsg(c *gin.Context, err error, errMsg string, statusCode int)
- func LoggingRespondError(c *gin.Context, err error, statusCode int)
- func NewShutdownError(message string) error
- func Respond(c *gin.Context, data any, statusCode int)
- func ValidateRequest(request any) error
- type ErrorResponse
- type FieldError
- type SafeError
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads an HTTP request body looking for a JSON document. The body is decoded into the value provided.
The provided value is checked for validation tags if it's a struct.
func GetQueryValue ¶
GetQueryValue is a utility to get a parameter value from the query string, nil if not found
func IsShutdown ¶
IsShutdown checks to see if the shutdown error is contained in the specified error value.
func LoggingRespondErrMsg ¶
LoggingRespondErrMsg sends an error response back to the client as a safe error from a msg
func LoggingRespondErrWithMsg ¶
LoggingRespondErrWithMsg sends an error response back to the client as a safe error from an error and msg
func LoggingRespondError ¶
LoggingRespondError sends an error response back to the client as a safe error
func NewShutdownError ¶
NewShutdownError returns an error that causes the framework to signal. a graceful shutdown
func ValidateRequest ¶
Types ¶
type ErrorResponse ¶
ErrorResponse is the structure of response error payloads sent back to the requester when validation of a request payload fails.
type FieldError ¶
FieldError is used to indicate an error with a field in a request payload.
type SafeError ¶
type SafeError struct { Err error StatusCode int Fields []FieldError }
SafeError is used to pass an error during the request through the server with web specific context. 'Safe' here means that the error messages do not include any sensitive information and can be sent straight back to the requester
func (*SafeError) Error ¶
SafeError implements the `error` interface. It uses the default message of the wrapped error. This is what will be shown in a server's logs
func (*SafeError) FieldErrors ¶
FieldErrors returns a string containing all field errors.
type Server ¶
Server is the entrypoint into our application and what configures our context object for each of our http router. Feel free to add any configuration data/logic on this Server struct.
func (*Server) PreShutdownHooks ¶
PreShutdownHooks runs all hooks that were registered by calling RegisterPreShutdownHook.