framework

package
v0.0.0-...-ef7a112 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r *http.Request, val any) error

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 GetParam

func GetParam(c *gin.Context, param string) *string

GetParam is a utility to get a path parameter from context, nil if not found

func GetQueryValue

func GetQueryValue(c *gin.Context, param string) *string

GetQueryValue is a utility to get a parameter value from the query string, nil if not found

func IsShutdown

func IsShutdown(err error) bool

IsShutdown checks to see if the shutdown error is contained in the specified error value.

func LoggingRespondErrMsg

func LoggingRespondErrMsg(c *gin.Context, errMsg string, statusCode int)

LoggingRespondErrMsg sends an error response back to the client as a safe error from a msg

func LoggingRespondErrWithMsg

func LoggingRespondErrWithMsg(c *gin.Context, err error, errMsg string, statusCode int)

LoggingRespondErrWithMsg sends an error response back to the client as a safe error from an error and msg

func LoggingRespondError

func LoggingRespondError(c *gin.Context, err error, statusCode int)

LoggingRespondError sends an error response back to the client as a safe error

func NewShutdownError

func NewShutdownError(message string) error

NewShutdownError returns an error that causes the framework to signal. a graceful shutdown

func PeekRequestBody

func PeekRequestBody(r *http.Request) (string, error)

PeekRequestBody reads a request's body without emptying the buffer

func Respond

func Respond(c *gin.Context, data any, statusCode int)

Respond convert a Go value to JSON and sends it to the client.

func SetupEngine

func SetupEngine(ctx context.Context, c config.ServerConfig) *gin.Engine

func ValidateRequest

func ValidateRequest(request any) error

Types

type ErrorResponse

type ErrorResponse struct {
	Error  string `json:"error"`
	Fields string `json:"fields,omitempty"`
}

ErrorResponse is the structure of response error payloads sent back to the requester when validation of a request payload fails.

type FieldError

type FieldError struct {
	Field string `json:"field"`
	Error string `json:"error"`
}

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

func (err *SafeError) Error() string

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

func (err *SafeError) FieldErrors() string

FieldErrors returns a string containing all field errors.

Jump to

Keyboard shortcuts

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