webhookutils

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleAPIError

func HandleAPIError(
	l *zerolog.Logger,
	alerter hatcheterrors.Alerter,
	w http.ResponseWriter,
	r *http.Request,
	err error,
	writeErr bool,
)

Types

type Decoder

type Decoder interface {
	// Decode accepts a target struct, a reader for the request body, and a URL
	// for the request endpoint
	Decode(s interface{}, r *http.Request) error

	// DecodeQueryOnly is Decode but only looks at the query parameters
	DecodeQueryOnly(s interface{}, r *http.Request) error
}

Decoder populates a request form from the request body and URL.

func NewDefaultDecoder

func NewDefaultDecoder() Decoder

NewDefaultDecoder returns an implementation of Decoder that uses `json` and `gorilla/schema`.

type DefaultDecoder

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

DefaultDecoder decodes the request body with `json` and the URL query params with gorilla/schema,

func (*DefaultDecoder) Decode

func (d *DefaultDecoder) Decode(
	s interface{},
	r *http.Request,
) error

Decode reads the request and populates the target request object.

func (*DefaultDecoder) DecodeQueryOnly

func (d *DefaultDecoder) DecodeQueryOnly(
	s interface{},
	r *http.Request,
) error

Decode reads the request and populates the target request object.

type DefaultRequestDecoderValidator

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

func (*DefaultRequestDecoderValidator) DecodeAndValidate

func (j *DefaultRequestDecoderValidator) DecodeAndValidate(
	w http.ResponseWriter,
	r *http.Request,
	v interface{},
) (ok bool)

func (*DefaultRequestDecoderValidator) DecodeAndValidateNoWrite

func (j *DefaultRequestDecoderValidator) DecodeAndValidateNoWrite(
	r *http.Request,
	v interface{},
) error

func (*DefaultRequestDecoderValidator) DecodeAndValidateQueryOnly

func (j *DefaultRequestDecoderValidator) DecodeAndValidateQueryOnly(
	w http.ResponseWriter,
	r *http.Request,
	v interface{},
) (ok bool)

type DefaultResultWriter

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

default generalizes response codes for common operations (http.StatusOK, http.StatusCreated, etc)

func (*DefaultResultWriter) WriteResult

func (j *DefaultResultWriter) WriteResult(w http.ResponseWriter, r *http.Request, v interface{})

type ErrorOpts

type ErrorOpts struct {
	Code uint
}

type RequestDecoderValidator

type RequestDecoderValidator interface {
	DecodeAndValidate(w http.ResponseWriter, r *http.Request, v interface{}) bool
	DecodeAndValidateQueryOnly(w http.ResponseWriter, r *http.Request, v interface{}) bool
	DecodeAndValidateNoWrite(r *http.Request, v interface{}) error
}

func NewDefaultRequestDecoderValidator

func NewDefaultRequestDecoderValidator(
	logger *zerolog.Logger,
	alerter errors.Alerter,
) RequestDecoderValidator

type ResultWriter

type ResultWriter interface {
	WriteResult(w http.ResponseWriter, r *http.Request, v interface{})
}

func NewDefaultResultWriter

func NewDefaultResultWriter(
	logger *zerolog.Logger,
	alerter hatcheterrors.Alerter,
) ResultWriter

Jump to

Keyboard shortcuts

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