httpio

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 12 Imported by: 0

README

httpio

The httpio package provides tools for decoding HTTP requests, decoding url parameters, and encoding HTTP responses in Go, complete with validation rules.

Getting Started

First, get the package by running:

go get github.com/cccteam/httpio

Decoder

The Decoder struct is used to decode and validate HTTP requests. It utilizes the json.NewDecoder() function to decode the HTTP request body into a provided struct.

Validation is handled by the Validator interface, which requires a Struct(s interface{}) error function. This function is expected to validate the struct s and return an error if the validation fails.

Example usage
type MyRequest struct {
    Field1 string `json:"field1" validate:"required"`
    Field2 int    `json:"field2" validate:"required,gt=0"`
}

v := validator.New()

func MyHandler(w http.ResponseWriter, r *http.Request) {
    req := &MyRequest{}
    validatorFunc :=  func(s interface{}) error {

        if err := v.Struct(s); err != nil {
            return err
        }

        return nil
    }

    decoder := httpio.NewDecoder(r, validatorFunc)
    if err := decoder.Decode(req); err != nil {
        // handle error
        return
    }
    // continue processing the request...
}

Encoder

The Encoder struct is used to encode HTTP responses. It has an implementation of the json.NewEncoder() function to encode a provided struct into the HTTP response body. The Encoder also allows for setting HTTP status codes and headers.

For usage of Encoder, please refer to the httpio package's source code.

Example usage

Here's an example of how to use Encoder:

type MyResponse struct {
    Message string `json:"message"`
    Code    int    `json:"code"`
}

func MyHandler(w http.ResponseWriter, r *http.Request) {
    // create response body
    responseBody := &MyResponse{
        Message: "Hello, world!",
        Code:    http.StatusOK,
    }

    // encode and send the response
    if err := httpio.NewEncoder(w).Ok(responseBody); err != nil {
        // handle error
        return
    }
}

The Encoder struct also provides methods to handle errors and encode HTTP error responses. Here's an example:

func MyHandler(w http.ResponseWriter, r *http.Request) {
    // some operation that may cause an error
    err := someOperation()
    if err != nil {
        // if the operation fails, return an Internal Server Error
        httpio.NewEncoder(w).InternalServerErrorWithMessage("This is what is returned in the response message", err)
        return
    }

    // if the operation is successful, proceed as normal...
}

Params

The Params() generic function serves as an enhancement to the chi router's parameters feature by decoding HTTP URL parameters into native Go types.

Currently the supported types are string, int, int64, float64, bool, and any type that implements the encoding.TextUnmarshaler interface.

Example usage
// given url: http://myapi.com/api/fileid/26
// and chi route of:          /api/fileid/{fileId}

func MyHandler(w http.ResponseWriter, r *http.Request) {
    param := Param[int64](r, "fileId")
    // param is parsed as type int64
    //
    // WithParams() middleware should be used to catch parsing errors
}

License

This project is licensed under the MIT License.

Documentation

Overview

httpio handles encoding and decoding for http i/o. This package is used to standardize request and response handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CauseIsError added in v0.2.0

func CauseIsError(err error) bool

CauseIsError returns true if the Cause of this error is an error vs a ClientMessage with nil error

func HasBadRequest added in v0.2.0

func HasBadRequest(err error) bool

HasBadRequest checks if the error contains a BadRequest (400) message

func HasClientMessage added in v0.2.0

func HasClientMessage(err error) bool

HasClientMessage checks if the error contains a client message

func HasConflict added in v0.2.0

func HasConflict(err error) bool

HasConflict checks if the error contains a Conflict (409) message

func HasForbidden added in v0.2.0

func HasForbidden(err error) bool

HasForbidden checks if the error contains a Forbidden (403) message

func HasInternalServerError added in v0.2.0

func HasInternalServerError(err error) bool

HasInternalServerError checks if the error contains an InternalServerError (500) message

func HasNotFound added in v0.2.0

func HasNotFound(err error) bool

HasNotFound checks if the error contains a NotFound (404) message

func HasServiceUnavailable added in v0.2.0

func HasServiceUnavailable(err error) bool

HasServiceUnavailable checks if the error contains a ServiceUnavailable (503) message

func HasUnauthorized added in v0.2.0

func HasUnauthorized(err error) bool

HasUnauthorized checks if the error contains an Unauthorized (401) message

func Message added in v0.2.0

func Message(err error) string

Message returns the message from the wrapped ClientMessage or an empty string

func Messages added in v0.2.0

func Messages(err error) []string

Messages returns a slice of messages from the ClientMessage's contained within the chain of errors

func NewBadRequest added in v0.2.0

func NewBadRequest() errors.Chain

NewBadRequest creates a new empty client message with a BadRequest (400) return code

func NewBadRequestMessage added in v0.2.0

func NewBadRequestMessage(message string) errors.Chain

NewBadRequestMessage creates a new client message with a BadRequest (400) return code

func NewBadRequestMessageWithError added in v0.2.0

func NewBadRequestMessageWithError(err error, message string) errors.Chain

NewBadRequestMessageWithError wraps an existing error while creating a new client message with a BadRequest (400) return code

func NewBadRequestMessageWithErrorf added in v0.2.0

func NewBadRequestMessageWithErrorf(err error, format string, a ...any) errors.Chain

NewBadRequestMessageWithErrorf wraps an existing error while creating a new client message with a BadRequest (400) return code

func NewBadRequestMessagef added in v0.2.0

func NewBadRequestMessagef(format string, a ...any) errors.Chain

NewBadRequestMessagef creates a new client message with a BadRequest (400) return code

func NewBadRequestWithError added in v0.2.0

func NewBadRequestWithError(err error) errors.Chain

NewBadRequestWithError wraps an existing error while creating a new empty client message and a BadRequest (400) return code

func NewConflict added in v0.2.0

func NewConflict() errors.Chain

NewConflict creates a new empty client message with a Conflict (409) return code

func NewConflictMessage added in v0.2.0

func NewConflictMessage(message string) errors.Chain

NewConflictMessage creates a new client message with a Conflict (409) return code

func NewConflictMessageWithError added in v0.2.0

func NewConflictMessageWithError(err error, message string) errors.Chain

NewConflictMessageWithError wraps an existing error while creating a new client message with a Conflict (409) return code

func NewConflictMessageWithErrorf added in v0.2.0

func NewConflictMessageWithErrorf(err error, format string, a ...any) errors.Chain

NewConflictMessageWithErrorf wraps an existing error while creating a new client message with a Conflict (409) return code

func NewConflictMessagef added in v0.2.0

func NewConflictMessagef(format string, a ...any) errors.Chain

NewConflictMessagef creates a new client message with a Conflict (409) return code

func NewConflictWithError added in v0.2.0

func NewConflictWithError(err error) errors.Chain

NewConflictWithError wraps an existing error while creating a new empty client message and a Conflict (409) return code

func NewForbidden added in v0.2.0

func NewForbidden() errors.Chain

NewForbidden creates a new empty client message with a Forbidden (403) return code

func NewForbiddenMessage added in v0.2.0

func NewForbiddenMessage(message string) errors.Chain

NewForbiddenMessage creates a new client message with a Forbidden (403) return code

func NewForbiddenMessageWithError added in v0.2.0

func NewForbiddenMessageWithError(err error, message string) errors.Chain

NewForbiddenMessageWithError wraps an existing error while creating a new client message with a Forbidden (403) return code

func NewForbiddenMessageWithErrorf added in v0.2.0

func NewForbiddenMessageWithErrorf(err error, format string, a ...any) errors.Chain

NewForbiddenMessageWithErrorf wraps an existing error while creating a new client message with a Forbidden (403) return code

func NewForbiddenMessagef added in v0.2.0

func NewForbiddenMessagef(format string, a ...any) errors.Chain

NewForbiddenMessagef creates a new client message with a Forbidden (403) return code

func NewForbiddenWithError added in v0.2.0

func NewForbiddenWithError(err error) errors.Chain

NewForbiddenWithError wraps an existing error while creating a new empty client message and a Forbidden (403) return code

func NewInternalServerError added in v0.2.0

func NewInternalServerError() errors.Chain

NewInternalServerError creates a new empty client message with a InternalServerError (500) return code

func NewInternalServerErrorMessage added in v0.2.0

func NewInternalServerErrorMessage(message string) errors.Chain

NewInternalServerErrorMessage creates a new client message with a InternalServerError (500) return code

func NewInternalServerErrorMessageWithError added in v0.2.0

func NewInternalServerErrorMessageWithError(err error, message string) errors.Chain

NewInternalServerErrorMessageWithError wraps an existing error while creating a new client message with a InternalServerError (500) return code

func NewInternalServerErrorMessageWithErrorf added in v0.2.0

func NewInternalServerErrorMessageWithErrorf(err error, format string, a ...any) errors.Chain

NewInternalServerErrorMessageWithErrorf wraps an existing error while creating a new client message with a InternalServerError (500) return code

func NewInternalServerErrorMessagef added in v0.2.0

func NewInternalServerErrorMessagef(format string, a ...any) errors.Chain

NewInternalServerErrorMessagef creates a new client message with a InternalServerError (500) return code

func NewInternalServerErrorWithError added in v0.2.0

func NewInternalServerErrorWithError(err error) errors.Chain

NewInternalServerErrorWithError wraps an existing error while creating a new empty client message and a InternalServerError (500) return code

func NewNotFound added in v0.2.0

func NewNotFound() errors.Chain

NewNotFound creates a new empty client message with a NotFound (404) return code

func NewNotFoundMessage added in v0.2.0

func NewNotFoundMessage(message string) errors.Chain

NewNotFoundMessage creates a new client message with a NotFound (404) return code

func NewNotFoundMessageWithError added in v0.2.0

func NewNotFoundMessageWithError(err error, message string) errors.Chain

NewNotFoundMessageWithError wraps an existing error while creating a new client message with a NotFound (404) return code

func NewNotFoundMessageWithErrorf added in v0.2.0

func NewNotFoundMessageWithErrorf(err error, format string, a ...any) errors.Chain

NewNotFoundMessageWithErrorf wraps an existing error while creating a new client message with a NotFound (404) return code

func NewNotFoundMessagef added in v0.2.0

func NewNotFoundMessagef(format string, a ...any) errors.Chain

NewNotFoundMessagef creates a new client message with a NotFound (404) return code

func NewNotFoundWithError added in v0.2.0

func NewNotFoundWithError(err error) errors.Chain

NewNotFoundWithError wraps an existing error while creating a new empty client message and a NotFound (404) return code

func NewServiceUnavailable added in v0.2.0

func NewServiceUnavailable() errors.Chain

NewServiceUnavailable creates a new empty client message with a ServiceUnavailable (503) return code

func NewServiceUnavailableMessage added in v0.2.0

func NewServiceUnavailableMessage(message string) errors.Chain

NewServiceUnavailableMessage creates a new client message with a ServiceUnavailable (503) return code

func NewServiceUnavailableMessageWithError added in v0.2.0

func NewServiceUnavailableMessageWithError(err error, message string) errors.Chain

NewServiceUnavailableMessageWithError wraps an existing error while creating a new client message with a ServiceUnavailable (503) return code

func NewServiceUnavailableMessageWithErrorf added in v0.2.0

func NewServiceUnavailableMessageWithErrorf(err error, format string, a ...any) errors.Chain

NewServiceUnavailableMessageWithErrorf wraps an existing error while creating a new client message with a ServiceUnavailable (503) return code

func NewServiceUnavailableMessagef added in v0.2.0

func NewServiceUnavailableMessagef(format string, a ...any) errors.Chain

NewServiceUnavailableMessagef creates a new client message with a ServiceUnavailable (503) return code

func NewServiceUnavailableWithError added in v0.2.0

func NewServiceUnavailableWithError(err error) errors.Chain

NewServiceUnavailableWithError wraps an existing error while creating a new empty client message and a ServiceUnavailable (503) return code

func NewUnauthorized added in v0.2.0

func NewUnauthorized() errors.Chain

NewUnauthorized creates a new empty client message with a Unauthorized (401) return code

func NewUnauthorizedMessage added in v0.2.0

func NewUnauthorizedMessage(message string) errors.Chain

NewUnauthorizedMessage creates a new client message with a Unauthorized (401) return code

func NewUnauthorizedMessageWithError added in v0.2.0

func NewUnauthorizedMessageWithError(err error, message string) errors.Chain

NewUnauthorizedMessageWithError wraps an existing error while creating a new client message with a Unauthorized (401) return code

func NewUnauthorizedMessageWithErrorf added in v0.2.0

func NewUnauthorizedMessageWithErrorf(err error, format string, a ...any) errors.Chain

NewUnauthorizedMessageWithErrorf wraps an existing error while creating a new client message with a Unauthorized (401) return code

func NewUnauthorizedMessagef added in v0.2.0

func NewUnauthorizedMessagef(format string, a ...any) errors.Chain

NewUnauthorizedMessagef creates a new client message with a Unauthorized (401) return code

func NewUnauthorizedWithError added in v0.2.0

func NewUnauthorizedWithError(err error) errors.Chain

NewUnauthorizedWithError wraps an existing error while creating a new empty client message and a Unauthorized (401) return code

func Param added in v0.0.2

func Param[T any](r *http.Request, param ParamType) (val T)

Param extracts the Param from the Request Context

func WithParams added in v0.0.2

func WithParams(next http.Handler) http.Handler

WithParams middleware is used to capture Param Parsing errors. They are returned as a http.StatusBadRequest status code with a message describing any parsing issue

Types

type ClientMessage added in v0.2.0

type ClientMessage struct {
	// contains filtered or unexported fields
}

ClientMessage is a custom message type that can be used to return client messages

func (*ClientMessage) Error added in v0.2.0

func (c *ClientMessage) Error() string

Error returns the error message

func (*ClientMessage) Message added in v0.2.0

func (c *ClientMessage) Message() string

Message returns the client message

func (*ClientMessage) Unwrap added in v0.2.0

func (c *ClientMessage) Unwrap() error

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder is a struct that can be used for decoding http requests and validating those requests

func NewDecoder

func NewDecoder(req *http.Request, validator ValidatorFunc) *Decoder

NewDecoder returns a pointer to a new Decoder struct

func (*Decoder) Decode

func (d *Decoder) Decode(request interface{}) error

Decode parses the http request body and validates it against the struct validation rules

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder is a struct that is used for encoding http responses

func NewEncoder

func NewEncoder(w http.ResponseWriter) *Encoder

NewEncoder returns a new Encoder to write to the ResponseWriter This encoder will write to the ResponseWriter using a json encoder.

func (*Encoder) BadRequest

func (e *Encoder) BadRequest(ctx context.Context) error

BadRequest creates a new empty client message with a BadRequest (400) return code

func (*Encoder) BadRequestMessage added in v0.2.0

func (e *Encoder) BadRequestMessage(ctx context.Context, message string) error

BadRequestMessage creates a new client message with a BadRequest (400) return code

func (*Encoder) BadRequestMessageWithError added in v0.2.0

func (e *Encoder) BadRequestMessageWithError(ctx context.Context, err error, message string) error

BadRequestMessageWithError wraps an existing error while creating a new client message with a BadRequest (400) return code

func (*Encoder) BadRequestMessageWithErrorf added in v0.2.0

func (e *Encoder) BadRequestMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error

BadRequestMessageWithErrorf wraps an existing error while creating a new client message with a BadRequest (400) return code

func (*Encoder) BadRequestMessagef added in v0.2.0

func (e *Encoder) BadRequestMessagef(ctx context.Context, format string, a ...any) error

BadRequestMessagef creates a new client message with a BadRequest (400) return code

func (*Encoder) BadRequestWithError added in v0.2.0

func (e *Encoder) BadRequestWithError(ctx context.Context, err error) error

BadRequestWithError wraps an existing error while creating a new empty client message and a BadRequest (400) return code

func (*Encoder) ClientMessage added in v0.2.0

func (e *Encoder) ClientMessage(ctx context.Context, err error) error

ClientMessage sets an http code and formats a client message based upon the message type found in the error chain. If no message type is found it defaults to InternalServerError (500) with no message

func (*Encoder) Conflict

func (e *Encoder) Conflict(ctx context.Context) error

Conflict creates a new empty client message with a Conflict (409) return code

func (*Encoder) ConflictMessage added in v0.2.0

func (e *Encoder) ConflictMessage(ctx context.Context, message string) error

ConflictMessage creates a new client message with a Conflict (409) return code

func (*Encoder) ConflictMessageWithError added in v0.2.0

func (e *Encoder) ConflictMessageWithError(ctx context.Context, err error, message string) error

ConflictMessageWithError wraps an existing error while creating a new client message with a Conflict (409) return code

func (*Encoder) ConflictMessageWithErrorf added in v0.2.0

func (e *Encoder) ConflictMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error

ConflictMessageWithErrorf wraps an existing error while creating a new client message with a Conflict (409) return code

func (*Encoder) ConflictMessagef added in v0.2.0

func (e *Encoder) ConflictMessagef(ctx context.Context, format string, a ...any) error

ConflictMessagef creates a new client message with a Conflict (409) return code

func (*Encoder) ConflictWithError added in v0.2.0

func (e *Encoder) ConflictWithError(ctx context.Context, err error) error

ConflictWithError wraps an existing error while creating a new empty client message and a Conflict (409) return code

func (*Encoder) Forbidden

func (e *Encoder) Forbidden(ctx context.Context) error

Forbidden creates a new empty client message with a Forbidden (403) return code

func (*Encoder) ForbiddenMessage added in v0.2.0

func (e *Encoder) ForbiddenMessage(ctx context.Context, message string) error

ForbiddenMessage creates a new client message with a Forbidden (403) return code

func (*Encoder) ForbiddenMessageWithError added in v0.2.0

func (e *Encoder) ForbiddenMessageWithError(ctx context.Context, err error, message string) error

ForbiddenMessageWithError wraps an existing error while creating a new client message with a Forbidden (403) return code

func (*Encoder) ForbiddenMessageWithErrorf added in v0.2.0

func (e *Encoder) ForbiddenMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error

ForbiddenMessageWithErrorf wraps an existing error while creating a new client message with a Forbidden (403) return code

func (*Encoder) ForbiddenMessagef added in v0.2.0

func (e *Encoder) ForbiddenMessagef(ctx context.Context, format string, a ...any) error

ForbiddenMessagef creates a new client message with a Forbidden (403) return code

func (*Encoder) ForbiddenWithError added in v0.2.0

func (e *Encoder) ForbiddenWithError(ctx context.Context, err error) error

ForbiddenWithError wraps an existing error while creating a new empty client message and a Forbidden (403) return code

func (*Encoder) InternalServerError

func (e *Encoder) InternalServerError(ctx context.Context) error

InternalServerError creates a new empty client message with a InternalServerError (500) return code

func (*Encoder) InternalServerErrorMessage added in v0.2.0

func (e *Encoder) InternalServerErrorMessage(ctx context.Context, message string) error

InternalServerErrorMessage creates a new client message with a InternalServerError (500) return code

func (*Encoder) InternalServerErrorMessageWithError added in v0.2.0

func (e *Encoder) InternalServerErrorMessageWithError(ctx context.Context, err error, message string) error

InternalServerErrorMessageWithError wraps an existing error while creating a new client message with a InternalServerError (500) return code

func (*Encoder) InternalServerErrorMessageWithErrorf added in v0.2.0

func (e *Encoder) InternalServerErrorMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error

InternalServerErrorMessageWithErrorf wraps an existing error while creating a new client message with a InternalServerError (500) return code

func (*Encoder) InternalServerErrorMessagef added in v0.2.0

func (e *Encoder) InternalServerErrorMessagef(ctx context.Context, format string, a ...any) error

InternalServerErrorMessagef creates a new client message with a InternalServerError (500) return code

func (*Encoder) InternalServerErrorWithError added in v0.2.0

func (e *Encoder) InternalServerErrorWithError(ctx context.Context, err error) error

InternalServerErrorWithError wraps an existing error while creating a new empty client message and a InternalServerError (500) return code

func (*Encoder) NotFound

func (e *Encoder) NotFound(ctx context.Context) error

NotFound creates a new empty client message with a NotFound (404) return code

func (*Encoder) NotFoundMessage added in v0.2.0

func (e *Encoder) NotFoundMessage(ctx context.Context, message string) error

NotFoundMessage creates a new client message with a NotFound (404) return code

func (*Encoder) NotFoundMessageWithError added in v0.2.0

func (e *Encoder) NotFoundMessageWithError(ctx context.Context, err error, message string) error

NotFoundMessageWithError wraps an existing error while creating a new client message with a NotFound (404) return code

func (*Encoder) NotFoundMessageWithErrorf added in v0.2.0

func (e *Encoder) NotFoundMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error

NotFoundMessageWithErrorf wraps an existing error while creating a new client message with a NotFound (404) return code

func (*Encoder) NotFoundMessagef added in v0.2.0

func (e *Encoder) NotFoundMessagef(ctx context.Context, format string, a ...any) error

NotFoundMessagef creates a new client message with a NotFound (404) return code

func (*Encoder) NotFoundWithError added in v0.2.0

func (e *Encoder) NotFoundWithError(ctx context.Context, err error) error

NotFoundWithError wraps an existing error while creating a new empty client message and a NotFound (404) return code

func (*Encoder) Ok

func (e *Encoder) Ok(body interface{}) error

Ok returns a default http 200 status response with a body

func (*Encoder) ServiceUnavailable

func (e *Encoder) ServiceUnavailable(ctx context.Context) error

ServiceUnavailable creates a new empty client message with a ServiceUnavailable (503) return code

func (*Encoder) ServiceUnavailableMessage added in v0.2.0

func (e *Encoder) ServiceUnavailableMessage(ctx context.Context, message string) error

ServiceUnavailableMessage creates a new client message with a ServiceUnavailable (503) return code

func (*Encoder) ServiceUnavailableMessageWithError added in v0.2.0

func (e *Encoder) ServiceUnavailableMessageWithError(ctx context.Context, err error, message string) error

ServiceUnavailableMessageWithError wraps an existing error while creating a new client message with a ServiceUnavailable (503) return code

func (*Encoder) ServiceUnavailableMessageWithErrorf added in v0.2.0

func (e *Encoder) ServiceUnavailableMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error

ServiceUnavailableMessageWithErrorf wraps an existing error while creating a new client message with a ServiceUnavailable (503) return code

func (*Encoder) ServiceUnavailableMessagef added in v0.2.0

func (e *Encoder) ServiceUnavailableMessagef(ctx context.Context, format string, a ...any) error

ServiceUnavailableMessagef creates a new client message with a ServiceUnavailable (503) return code

func (*Encoder) ServiceUnavailableWithError added in v0.2.0

func (e *Encoder) ServiceUnavailableWithError(ctx context.Context, err error) error

ServiceUnavailableWithError wraps an existing error while creating a new empty client message and a ServiceUnavailable (503) return code

func (*Encoder) StatusCodeWithBody added in v0.2.0

func (e *Encoder) StatusCodeWithBody(statusCode int, body interface{}) error

StatusCodeWithBody writes a statusCode and body

func (*Encoder) Unauthorized

func (e *Encoder) Unauthorized(ctx context.Context) error

Unauthorized creates a new empty client message with a Unauthorized (401) return code

func (*Encoder) UnauthorizedMessage added in v0.2.0

func (e *Encoder) UnauthorizedMessage(ctx context.Context, message string) error

UnauthorizedMessage creates a new client message with a Unauthorized (401) return code

func (*Encoder) UnauthorizedMessageWithError added in v0.2.0

func (e *Encoder) UnauthorizedMessageWithError(ctx context.Context, err error, message string) error

UnauthorizedMessageWithError wraps an existing error while creating a new client message with a Unauthorized (401) return code

func (*Encoder) UnauthorizedMessageWithErrorf added in v0.2.0

func (e *Encoder) UnauthorizedMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error

UnauthorizedMessageWithErrorf wraps an existing error while creating a new client message with a Unauthorized (401) return code

func (*Encoder) UnauthorizedMessagef added in v0.2.0

func (e *Encoder) UnauthorizedMessagef(ctx context.Context, format string, a ...any) error

UnauthorizedMessagef creates a new client message with a Unauthorized (401) return code

func (*Encoder) UnauthorizedWithError added in v0.2.0

func (e *Encoder) UnauthorizedWithError(ctx context.Context, err error) error

UnauthorizedWithError wraps an existing error while creating a new empty client message and a Unauthorized (401) return code

type HTTPEncoder

type HTTPEncoder interface {
	// Encode is the call that is made to encode data into a response body and returns an error if it fails
	Encode(v interface{}) error
}

HTTPEncoder is an interface that is accepted when encoding http responses

type MessageResponse

type MessageResponse struct {
	Message string `json:"message,omitempty"`
	TraceID string `json:"traceId,omitempty"`
}

MessageResponse holds a standard structure for http responses that carry a single message This also includes a trace ID for debugging purposes

type ParamType added in v0.0.2

type ParamType string

ParamType defines the type used to describe url Params

type ValidatorFunc

type ValidatorFunc func(s interface{}) error

ValidatorFunc is a function that validates s It returns an error if the validation fails

Jump to

Keyboard shortcuts

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