halt

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 2 Imported by: 2

README

halt

General halt error for Go

Credits

GUO YANKE, MIT License

Documentation

Index

Constants

View Source
const (
	ExtraKeyMessage = "message"
)

Variables

This section is empty.

Functions

func Error

func Error(err error, opts ...Option)

Error panic with new Halt

func GetExtras

func GetExtras(err error) (m map[string]any)

GetExtras get extras from previous created halt error

func GetStatusCode

func GetStatusCode(err error) int

GetStatusCode get status code from previous created halt error

func New

func New(err error, opts ...Option) error

New create a new Halt as an error

func String

func String(s string, opts ...Option)

String panic with new Halt with plain string

Types

type Halt

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

func (*Halt) ExtractExtras

func (h *Halt) ExtractExtras(m map[string]any)

func (*Halt) StatusCode

func (h *Halt) StatusCode() int

func (*Halt) Unwrap

func (h *Halt) Unwrap() error

type Option

type Option func(h *Halt)

Option configuration function for Halt

func WithBadRequest

func WithBadRequest() Option

WithBadRequest alias to WithStatusCode with http.StatusBadRequest

func WithExtra

func WithExtra(k string, v any) Option

WithExtra a Option setting extras with a key-value

func WithExtras

func WithExtras(m map[string]any) Option

WithExtras a Option setting extras with key-values

func WithMessage

func WithMessage(m string) Option

WithMessage a Option overriding message key

func WithStatusCode

func WithStatusCode(code int) Option

WithStatusCode a Option setting status code

Jump to

Keyboard shortcuts

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