external

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller interface {
	InitController(request any)

	// SetStatus sets the status code for the GleeceController.
	SetStatus(statusCode HttpStatusCode)

	// GetStatus gets the status code for the GleeceController.
	GetStatus() *HttpStatusCode

	// SetHeader sets a header for the GleeceController.
	SetHeader(name string, value string)

	// GetHeaders get headers set (defined using the `SetHeader` API).
	GetHeaders() map[string]string
}

type CustomError

type CustomError struct {
	Payload any
}

type GleeceController

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

GleeceController provides common functionality for controllers.

func (*GleeceController) GetHeaders added in v1.0.3

func (gc *GleeceController) GetHeaders() map[string]string

GetHeaders get headers set (defined using the `SetHeader` API).

func (*GleeceController) GetStatus

func (gc *GleeceController) GetStatus() *HttpStatusCode

GetStatus gets the status code for the GleeceController.

func (*GleeceController) InitController added in v1.0.3

func (gc *GleeceController) InitController(request any)

func (*GleeceController) SetHeader

func (gc *GleeceController) SetHeader(name string, value string)

SetHeader sets a header for the GleeceController.

func (*GleeceController) SetStatus

func (gc *GleeceController) SetStatus(statusCode HttpStatusCode)

SetStatus sets the status code for the GleeceController.

type HttpStatusCode

type HttpStatusCode uint
const (
	StatusContinue           HttpStatusCode = 100 // RFC 9110, 15.2.1
	StatusSwitchingProtocols HttpStatusCode = 101 // RFC 9110, 15.2.2
	StatusProcessing         HttpStatusCode = 102 // RFC 2518, 10.1
	StatusEarlyHints         HttpStatusCode = 103 // RFC 8297

	StatusOK                   HttpStatusCode = 200 // RFC 9110, 15.3.1
	StatusCreated              HttpStatusCode = 201 // RFC 9110, 15.3.2
	StatusAccepted             HttpStatusCode = 202 // RFC 9110, 15.3.3
	StatusNonAuthoritativeInfo HttpStatusCode = 203 // RFC 9110, 15.3.4
	StatusNoContent            HttpStatusCode = 204 // RFC 9110, 15.3.5
	StatusResetContent         HttpStatusCode = 205 // RFC 9110, 15.3.6
	StatusPartialContent       HttpStatusCode = 206 // RFC 9110, 15.3.7
	StatusMultiStatus          HttpStatusCode = 207 // RFC 4918, 11.1
	StatusAlreadyReported      HttpStatusCode = 208 // RFC 5842, 7.1
	StatusIMUsed               HttpStatusCode = 226 // RFC 3229, 10.4.1

	StatusMultipleChoices  HttpStatusCode = 300 // RFC 9110, 15.4.1
	StatusMovedPermanently HttpStatusCode = 301 // RFC 9110, 15.4.2
	StatusFound            HttpStatusCode = 302 // RFC 9110, 15.4.3
	StatusSeeOther         HttpStatusCode = 303 // RFC 9110, 15.4.4
	StatusNotModified      HttpStatusCode = 304 // RFC 9110, 15.4.5
	StatusUseProxy         HttpStatusCode = 305 // RFC 9110, 15.4.6

	StatusTemporaryRedirect HttpStatusCode = 307 // RFC 9110, 15.4.8
	StatusPermanentRedirect HttpStatusCode = 308 // RFC 9110, 15.4.9

	StatusBadRequest                   HttpStatusCode = 400 // RFC 9110, 15.5.1
	StatusUnauthorized                 HttpStatusCode = 401 // RFC 9110, 15.5.2
	StatusPaymentRequired              HttpStatusCode = 402 // RFC 9110, 15.5.3
	StatusForbidden                    HttpStatusCode = 403 // RFC 9110, 15.5.4
	StatusNotFound                     HttpStatusCode = 404 // RFC 9110, 15.5.5
	StatusMethodNotAllowed             HttpStatusCode = 405 // RFC 9110, 15.5.6
	StatusNotAcceptable                HttpStatusCode = 406 // RFC 9110, 15.5.7
	StatusProxyAuthRequired            HttpStatusCode = 407 // RFC 9110, 15.5.8
	StatusRequestTimeout               HttpStatusCode = 408 // RFC 9110, 15.5.9
	StatusConflict                     HttpStatusCode = 409 // RFC 9110, 15.5.10
	StatusGone                         HttpStatusCode = 410 // RFC 9110, 15.5.11
	StatusLengthRequired               HttpStatusCode = 411 // RFC 9110, 15.5.12
	StatusPreconditionFailed           HttpStatusCode = 412 // RFC 9110, 15.5.13
	StatusRequestEntityTooLarge        HttpStatusCode = 413 // RFC 9110, 15.5.14
	StatusRequestURITooLong            HttpStatusCode = 414 // RFC 9110, 15.5.15
	StatusUnsupportedMediaType         HttpStatusCode = 415 // RFC 9110, 15.5.16
	StatusRequestedRangeNotSatisfiable HttpStatusCode = 416 // RFC 9110, 15.5.17
	StatusExpectationFailed            HttpStatusCode = 417 // RFC 9110, 15.5.18
	StatusTeapot                       HttpStatusCode = 418 // RFC 9110, 15.5.19 (Unused)
	StatusMisdirectedRequest           HttpStatusCode = 421 // RFC 9110, 15.5.20
	StatusUnprocessableEntity          HttpStatusCode = 422 // RFC 9110, 15.5.21
	StatusLocked                       HttpStatusCode = 423 // RFC 4918, 11.3
	StatusFailedDependency             HttpStatusCode = 424 // RFC 4918, 11.4
	StatusTooEarly                     HttpStatusCode = 425 // RFC 8470, 5.2.
	StatusUpgradeRequired              HttpStatusCode = 426 // RFC 9110, 15.5.22
	StatusPreconditionRequired         HttpStatusCode = 428 // RFC 6585, 3
	StatusTooManyRequests              HttpStatusCode = 429 // RFC 6585, 4
	StatusRequestHeaderFieldsTooLarge  HttpStatusCode = 431 // RFC 6585, 5
	StatusUnavailableForLegalReasons   HttpStatusCode = 451 // RFC 7725, 3

	StatusInternalServerError           HttpStatusCode = 500 // RFC 9110, 15.6.1
	StatusNotImplemented                HttpStatusCode = 501 // RFC 9110, 15.6.2
	StatusBadGateway                    HttpStatusCode = 502 // RFC 9110, 15.6.3
	StatusServiceUnavailable            HttpStatusCode = 503 // RFC 9110, 15.6.4
	StatusGatewayTimeout                HttpStatusCode = 504 // RFC 9110, 15.6.5
	StatusHTTPVersionNotSupported       HttpStatusCode = 505 // RFC 9110, 15.6.6
	StatusVariantAlsoNegotiates         HttpStatusCode = 506 // RFC 2295, 8.1
	StatusInsufficientStorage           HttpStatusCode = 507 // RFC 4918, 11.5
	StatusLoopDetected                  HttpStatusCode = 508 // RFC 5842, 7.2
	StatusNotExtended                   HttpStatusCode = 510 // RFC 2774, 7
	StatusNetworkAuthenticationRequired HttpStatusCode = 511 // RFC 6585, 6
)

Taken from net/http Prefer to have this typed in-house as an 'enum'

type Rfc7807Error

type Rfc7807Error struct {
	Type       string            `json:"type"`
	Title      string            `json:"title"`
	Detail     string            `json:"detail"`
	Status     int               `json:"status"`
	Instance   string            `json:"instance"`
	Extensions map[string]string `json:"extensions"`
}

type SecurityCheck

type SecurityCheck struct {
	SchemaName string   `json:"name" validate:"required,starts_with_letter"`
	Scopes     []string `json:"scopes" validate:"not_nil_array"`
}

type SecurityError

type SecurityError struct {
	Message     string
	StatusCode  HttpStatusCode
	CustomError *CustomError
}

type ValidationFieldLevel

type ValidationFieldLevel interface {

	// Top returns the top level struct, if any
	Top() reflect.Value

	// Parent returns the current fields parent struct, if any or
	// the comparison value if called 'VarWithValue'
	Parent() reflect.Value

	// Field returns current field for validation
	Field() reflect.Value

	// FieldName returns the field's name with the tag
	// name taking precedence over the fields actual name.
	FieldName() string

	// StructFieldName returns the struct field's name
	StructFieldName() string

	// Param returns param for validation against current field
	Param() string

	// GetTag returns the current validations tag name
	GetTag() string

	// ExtractType gets the actual underlying type of field value.
	// It will dive into pointers, customTypes and return you the
	// underlying value and it's kind.
	ExtractType(field reflect.Value) (value reflect.Value, kind reflect.Kind, nullable bool)

	// GetStructFieldOK traverses the parent struct to retrieve a specific field denoted by the provided namespace
	// in the param and returns the field, field kind and whether is was successful in retrieving
	// the field at all.
	//
	// NOTE: when not successful ok will be false, this can happen when a nested struct is nil and so the field
	// could not be retrieved because it didn't exist.
	//
	// Deprecated: Use GetStructFieldOK2() instead which also return if the value is nullable.
	GetStructFieldOK() (reflect.Value, reflect.Kind, bool)

	// GetStructFieldOKAdvanced is the same as GetStructFieldOK except that it accepts the parent struct to start looking for
	// the field and namespace allowing more extensibility for validators.
	//
	// Deprecated: Use GetStructFieldOKAdvanced2() instead which also return if the value is nullable.
	GetStructFieldOKAdvanced(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool)

	// GetStructFieldOK2 traverses the parent struct to retrieve a specific field denoted by the provided namespace
	// in the param and returns the field, field kind, if it's a nullable type and whether is was successful in retrieving
	// the field at all.
	//
	// NOTE: when not successful ok will be false, this can happen when a nested struct is nil and so the field
	// could not be retrieved because it didn't exist.
	GetStructFieldOK2() (reflect.Value, reflect.Kind, bool, bool)

	// GetStructFieldOKAdvanced2 is the same as GetStructFieldOK except that it accepts the parent struct to start looking for
	// the field and namespace allowing more extensibility for validators.
	GetStructFieldOKAdvanced2(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool, bool)
}

Copy of the "FieldLevel" interface from the go-playground/validator package to decouple the package from the go-playground/validator specific version

type ValidationFunc

type ValidationFunc func(fl ValidationFieldLevel) bool

Copy of the "Func" type from the go-playground/validator package to decouple the package from the go-playground/validator specific version

Jump to

Keyboard shortcuts

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