nullable

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package nullable contains nullable types used to handle scenarios where default values can't be used to indicate empty, and we want to avoid using pointers for that.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidQueryParams = errors.New("invalid query parameters")

Functions

This section is empty.

Types

type Parser

type Parser[T nullable] func(string) (Value[T], error)

Parser[T any] represents a parser function. It is used to avoid a single parser for all nullables for improved readability and performance. Parser should always return Nullable with Set=true, error otherwise.

type Value

type Value[T any] struct {
	Valid bool
	Value T
}

Value type is used to represent difference betweeen an intentionally omitted value and default type value.

func New

func New[T nullable](v T) Value[T]

func Parse

func Parse[T nullable](q url.Values, key string, parser Parser[T]) (Value[T], error)

func ParseBool

func ParseBool(s string) (Value[bool], error)

func ParseFloat

func ParseFloat(s string) (Value[float64], error)

func ParseInt

func ParseInt(s string) (Value[int], error)

func ParseString

func ParseString(s string) (Value[string], error)

func ParseU16

func ParseU16(s string) (Value[uint16], error)

func ParseU64

func ParseU64(s string) (Value[uint64], error)

func (Value[T]) MarshalJSON

func (n Value[T]) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value if set, otherwise returns `null`.

func (*Value[T]) UnmarshalJSON

func (n *Value[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes JSON and sets the value and Set flag.

Jump to

Keyboard shortcuts

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