Documentation
¶
Index ¶
- func UndValidate[T validate.UndValidator](u Und[T]) error
- type SqlNull
- type Und
- func Defined[T any](t T) Und[T]
- func FromOption[T any](opt option.Option[option.Option[T]]) Und[T]
- func FromPointer[T any](v *T) Und[T]
- func FromSqlNull[T any](v sql.Null[T]) Und[T]
- func Map[T, U any](u Und[T], f func(t T) U) Und[U]
- func Null[T any]() Und[T]
- func Undefined[T any]() Und[T]
- func WrapPointer[T any](t *T) Und[*T]
- func (u Und[T]) Clone() Und[T]
- func (u Und[T]) CloneFunc(cloneT func(T) T) Und[T]
- func (u Und[T]) DoublePointer() **T
- func (u Und[T]) Equal(other Und[T]) bool
- func (u Und[T]) EqualFunc(other Und[T], cmp func(i, j T) bool) bool
- func (u Und[T]) IsDefined() bool
- func (u Und[T]) IsNull() bool
- func (u Und[T]) IsUndefined() bool
- func (u Und[T]) IsZero() bool
- func (u Und[T]) Iter() iter.Seq[option.Option[T]]
- func (u Und[T]) LogValue() slog.Value
- func (u Und[T]) Map(f func(option.Option[option.Option[T]]) option.Option[option.Option[T]]) Und[T]
- func (u Und[T]) MarshalJSON() ([]byte, error)
- func (u Und[T]) MarshalJSONV2(enc *jsontext.Encoder, opts jsonv2.Options) error
- func (o Und[T]) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (u Und[T]) Pointer() *T
- func (u Und[T]) SqlNull() sql.Null[T]
- func (u Und[T]) UndCheck() error
- func (u Und[T]) UndValidate() error
- func (u *Und[T]) UnmarshalJSON(data []byte) error
- func (u *Und[T]) UnmarshalJSONV2(dec *jsontext.Decoder, opts jsonv2.Options) error
- func (o *Und[T]) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- func (u Und[T]) Unwrap() option.Option[option.Option[T]]
- func (u Und[T]) Value() T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UndValidate ¶
func UndValidate[T validate.UndValidator](u Und[T]) error
Types ¶
type SqlNull ¶
SqlNull[T] adapts Und[T] to sql.Scanner and driver.Valuer.
func (*SqlNull[T]) Scan ¶
Scan implements sql.Scanner.
If T or *T implements sql.Scanner, the implementation is used. Otherwise, SqlNull[T] falls back to sql.Null[T] as sql.Scanner.
type Und ¶
type Und[T any] struct { // contains filtered or unexported fields }
Und[T] is a type that can express a value (`T`), empty (`null`), or absent (`undefined`). Und[T] is comparable if T is comparable. And it can be copied by assign.
Und[T] implements IsZero and is omitted when is a struct field of other structs and appropriate marshalers and appropriate struct tag on the field, e.g. "github.com/go-json-experiment/json/jsontext" with omitzero option set to the field, or "github.com/json-iterator/go" with omitempty option to the field and an appropriate extension.
If you need to stick with encoding/json v1, you can use github.com/ngicks/und/sliceund, a slice based version of Und[T] whish is already skppable by v1.
func FromOption ¶
FromOptions converts opt into an Und[T]. opt is retained by the returned value.
func FromPointer ¶
FromPointer converts *T into Und[T]. If v is nil, it returns an undefined Und. Otherwise, it returns Defined[T] whose value is the dereferenced v.
If you need to keep t as pointer, use WrapPointer instead.
func FromSqlNull ¶
FromSqlNull converts a valid sql.Null[T] to a defined Und[T] and invalid one into a null Und[].
func WrapPointer ¶
WrapPointer converts *T into Und[*T]. The und value is defined if t is non nil, undefined otherwise.
If you want t to be dereferenced, use FromPointer instead.
func (Und[T]) DoublePointer ¶
func (u Und[T]) DoublePointer() **T
DoublePointer returns nil if u is undefined, &(*T)(nil) if null, the internal value if defined.
func (Und[T]) Equal ¶
Equal implements Equality[Und[T]]. Equal panics if T is uncomparable and does not implement Equality[T].
func (Und[T]) EqualFunc ¶
EqualFunc reports whether two Und values are equal. EqualFunc checks state of both. If both state does not match, it returns false. If both are "defined" state, then checks equality of their value by cmp, then returns true if they are equal.
func (Und[T]) IsUndefined ¶
IsUndefined returns true if u is an undefined value, otherwise false.
func (Und[T]) Iter ¶
Iter returns an iterator over the internal option. If u is undefined, the iterator yields nothing, otherwise the internal option.
func (Und[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Und[T]) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
func (Und[T]) MarshalXML ¶
MarshalXML implements xml.Marshaler.
func (Und[T]) Pointer ¶
func (u Und[T]) Pointer() *T
Pointer returns u's internal value as a pointer.
func (Und[T]) UndValidate ¶
func (*Und[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Und[T]) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
func (*Und[T]) UnmarshalXML ¶
UnmarshalXML implements xml.Unmarshaler.
Directories
¶
| Path | Synopsis |
|---|---|
|
package conversion defines conversion helpers for code generated by github.com/ngicks/go-codegen/codegen
|
package conversion defines conversion helpers for code generated by github.com/ngicks/go-codegen/codegen |
|
internal
|
|
|
script/vendor_domestic
command
|
|