httputil

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindJSON

func BindJSON(v any, r io.Reader) error

func DisableTraceID

func DisableTraceID()

func EnableTraceID

func EnableTraceID()

func Errorf

func Errorf(statusCode, code int, format string, a ...any) error

func NewBasicAuth

func NewBasicAuth(next http.Handler, fc BasicAuthFunc) http.Handler

func NewStatus

func NewStatus(statusCode, code int, message string) error

func StatusWrap

func StatusWrap(statusCode, code int, err error) error

func StatusWrapE

func StatusWrapE(statusCode, code int, message string, err error) error

func TraceID

func TraceID() string

func WrapE

func WrapE(fc func(w http.ResponseWriter, r *http.Request) error) http.HandlerFunc

func XBindJSON

func XBindJSON[T any](r io.Reader) (T, error)

Types

type Ack

type Ack[T any] struct {
	Status  int    `json:"status"`
	Message string `json:"msg,omitempty"`
	Data    T      `json:"data,omitempty"`
}

type BasicAuthFunc

type BasicAuthFunc func(username, password string) bool

func NewMemoryBasicAuthFunc

func NewMemoryBasicAuthFunc(users map[string]string) BasicAuthFunc

type Caller

type Caller[T any] struct {
	// contains filtered or unexported fields
}

func Any

func Any(statusCode, code int) *Caller[any]

func NewAck

func NewAck[T any](statusCode, code int) *Caller[T]

func (*Caller[T]) Data

func (c *Caller[T]) Data(v T) *Caller[T]

func (*Caller[T]) GetTraceID

func (c *Caller[T]) GetTraceID() string

func (*Caller[T]) Message

func (c *Caller[T]) Message(m string) *Caller[T]

func (*Caller[T]) Ok

func (c *Caller[T]) Ok(w http.ResponseWriter)

func (*Caller[T]) TraceID

func (c *Caller[T]) TraceID(i string)

type Error

type Error struct {
	StatusCode int
	Code       int
	Message    string
}

func As

func As(err error) (*Error, bool)

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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