olhttp

package
v0.0.0-...-3655715 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrJSONDecodeEOF = errTypeJSONDecode.New("EOF - http body appears to be empty")
)

Functions

func FormBool

func FormBool(value url.Values, key string) bool

func GetBool

func GetBool(value url.Values, key string) app.Nullable[bool]

func GetBoolDefault

func GetBoolDefault(value url.Values, key string, defaultValue bool) bool

func GetID

func GetID(ctx context.Context) string

func GetIP

func GetIP(r *http.Request) net.IP

func GetInt32FromQuery

func GetInt32FromQuery(values url.Values, key string) app.Int32

func GetInt32RangeFromQuery

func GetInt32RangeFromQuery(query url.Values, queryParam string) app.Int32Range

func GetInt64Array

func GetInt64Array(value url.Values, key string) []int64

func GetPage

func GetPage(values url.Values, key string) uint32

func GetPageSize

func GetPageSize(values url.Values, key string, minValue, maxValue, defaultValue uint32) uint32

func GetRequest

func GetRequest(ctx context.Context) *http.Request

func GetStringArray

func GetStringArray(value url.Values, key string) []string

func GetUUIDArray

func GetUUIDArray(value url.Values, key string) []uuid.UUID

func IsSameURL

func IsSameURL(url *url.URL, str string) bool

func MakeRecoveryMiddleware

func MakeRecoveryMiddleware() func(next http.Handler) http.Handler

func ParseInt64Array

func ParseInt64Array(value string) []int64

func ParseInt64Slug

func ParseInt64Slug(slug string) (int64, string)

func ParseStringArray

func ParseStringArray(value string) []string

func PreferredMimeTypeIsJSON

func PreferredMimeTypeIsJSON(r *http.Request) bool

PreferredMimeTypeIsJSON checks if the client prefers JSON mime types more than other types

func ReadJSONBody

func ReadJSONBody(r *http.Request, v any) error

func ReqCtxMiddleware

func ReqCtxMiddleware(next http.Handler) http.Handler

func SplitByWithEscape

func SplitByWithEscape(s string, c byte) []string

func URLParamInt64

func URLParamInt64(r *http.Request, name string) (int64, error)

func URLParamUUID

func URLParamUUID(r *http.Request, name string) (uuid.UUID, error)

func URLQueryParamInt64

func URLQueryParamInt64(r *http.Request, name string) (int64, error)

func URLQueryParamUUID

func URLQueryParamUUID(r *http.Request, name string) (uuid.UUID, error)

func Write500

func Write500(
	w http.ResponseWriter,
	r *http.Request,
	err error,
)

func WriteCustomErrorPage

func WriteCustomErrorPage(
	w http.ResponseWriter,
	r *http.Request,
	title, subtitle string,
	err error,
)

func WriteTemplate

func WriteTemplate(w http.ResponseWriter, ctx context.Context, t templ.Component)

Types

type APIBody

type APIBody interface {
	WriteHttpBody(w http.ResponseWriter)
}

type APIResponse

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

func NewAPIError

func NewAPIError(err error) *APIResponse

func NewAPIErrorWithMessage

func NewAPIErrorWithMessage(message string) *APIResponse

func NewAPIResponse

func NewAPIResponse(data any) *APIResponse

func NewAPIResponseOK

func NewAPIResponseOK() *APIResponse

func (*APIResponse) AddNotification

func (r *APIResponse) AddNotification(notif Notification)

func (*APIResponse) Write

func (r *APIResponse) Write(w http.ResponseWriter)

type Notification

type Notification struct {
	Text string           `json:"text"`
	Type NotificationType `json:"type"`
}

func NewNotification

func NewNotification(text string, typ NotificationType) Notification

type NotificationType

type NotificationType uint8
const (
	NotificationInfo NotificationType = iota
	NotificationWarn
	NotificationError
)

func (NotificationType) MarshalJSON

func (n NotificationType) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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