field

package module
v1.173.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 8 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package field provides utilities to set structure fields. It was inspired by the kubernetes package https://pkg.go.dev/k8s.io/utils/pointer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[T comparable](a, b *T) bool

Equal returns true if both arguments are nil or both arguments dereference to the same value.

func EqualValue

func EqualValue[T comparable](field *T, value T) bool

EqualValue returns true if optional field dereferences to the value.

func NilIfEmpty

func NilIfEmpty[T any](v *T) *T

NilIfEmpty returns the given pointer unless it is empty and in that case returns nil. It is similar to ToOptionalOrNilIfEmpty but works on reference.

func Optional

func Optional[T any](p *T, defaultValue T) T

Optional returns the value of an optional field or else returns defaultValue.

func OptionalAny

func OptionalAny(ptr *any, defaultValue any) any

OptionalAny returns the value of an optional field or else returns defaultValue.

func OptionalBool

func OptionalBool(ptr *bool, defaultValue bool) bool

OptionalBool returns the value of an optional field or else returns defaultValue.

func OptionalDuration

func OptionalDuration(ptr *time.Duration, defaultValue time.Duration) time.Duration

OptionalDuration returns the value of an optional field or else returns defaultValue.

func OptionalFloat32

func OptionalFloat32(ptr *float32, defaultValue float32) float32

OptionalFloat32 returns the value of an optional field or else returns defaultValue.

func OptionalFloat64

func OptionalFloat64(ptr *float64, defaultValue float64) float64

OptionalFloat64 returns the value of an optional field or else returns defaultValue.

func OptionalInt

func OptionalInt(ptr *int, defaultValue int) int

OptionalInt returns the value of an optional field or else returns defaultValue.

func OptionalInt32

func OptionalInt32(ptr *int32, defaultValue int32) int32

OptionalInt32 returns the value of an optional field or else returns defaultValue.

func OptionalInt64

func OptionalInt64(ptr *int64, defaultValue int64) int64

OptionalInt64 returns the value of an optional field or else returns defaultValue.

func OptionalString

func OptionalString(ptr *string, defaultValue string) string

OptionalString returns the value of an optional field or else returns defaultValue.

func OptionalTime

func OptionalTime(ptr *time.Time, defaultValue time.Time) time.Time

OptionalTime returns the value of an optional field or else returns defaultValue.

func OptionalUint

func OptionalUint(ptr *uint, defaultValue uint) uint

OptionalUint returns the value of an optional field or else returns defaultValue.

func OptionalUint32

func OptionalUint32(ptr *uint32, defaultValue uint32) uint32

OptionalUint32 returns the value of an optional field or else returns defaultValue.

func OptionalUint64

func OptionalUint64(ptr *uint64, defaultValue uint64) uint64

OptionalUint64 returns the value of an optional field or else returns defaultValue.

func ToOptional

func ToOptional[T any](v T) *T

ToOptional returns a pointer to the given field value.

func ToOptionalAny

func ToOptionalAny(a any) *any

ToOptionalAny returns a pointer to an object.

func ToOptionalAnyOrNilIfEmpty

func ToOptionalAnyOrNilIfEmpty(f any) *any

ToOptionalAnyOrNilIfEmpty returns a pointer to an object unless it is empty and in that case returns nil.

func ToOptionalBool

func ToOptionalBool(b bool) *bool

ToOptionalBool returns a pointer to a bool.

func ToOptionalBoolOrNilIfEmpty

func ToOptionalBoolOrNilIfEmpty(f bool) *bool

ToOptionalBoolOrNilIfEmpty returns a pointer to a boolean unless it is empty and in that case returns nil.

func ToOptionalDuration

func ToOptionalDuration(f time.Duration) *time.Duration

ToOptionalDuration returns a pointer to a Duration.

func ToOptionalDurationOrNilIfEmpty

func ToOptionalDurationOrNilIfEmpty(f time.Duration) *time.Duration

ToOptionalDurationOrNilIfEmpty returns a pointer to a duration unless it is empty and in that case returns nil.

func ToOptionalFloat32

func ToOptionalFloat32(f float32) *float32

ToOptionalFloat32 returns a pointer to a float32.

func ToOptionalFloat32OrNilIfEmpty

func ToOptionalFloat32OrNilIfEmpty(f float32) *float32

ToOptionalFloat32OrNilIfEmpty returns a pointer to a float32 unless it is empty and in that case returns nil.

func ToOptionalFloat64

func ToOptionalFloat64(f float64) *float64

ToOptionalFloat64 returns a pointer to a float64.

func ToOptionalFloat64OrNilIfEmpty

func ToOptionalFloat64OrNilIfEmpty(f float64) *float64

ToOptionalFloat64OrNilIfEmpty returns a pointer to a float64 unless it is empty and in that case returns nil.

func ToOptionalInt

func ToOptionalInt(f int) *int

ToOptionalInt returns a pointer to an int

func ToOptionalInt32

func ToOptionalInt32(f int32) *int32

ToOptionalInt32 returns a pointer to an int32.

func ToOptionalInt32OrNilIfEmpty

func ToOptionalInt32OrNilIfEmpty(f int32) *int32

ToOptionalInt32OrNilIfEmpty returns a pointer to an int32 unless it is empty and in that case returns nil.

func ToOptionalInt64

func ToOptionalInt64(f int64) *int64

ToOptionalInt64 returns a pointer to an int64.

func ToOptionalInt64OrNilIfEmpty

func ToOptionalInt64OrNilIfEmpty(f int64) *int64

ToOptionalInt64OrNilIfEmpty returns a pointer to an int64 unless it is empty and in that case returns nil.

func ToOptionalIntOrNilIfEmpty

func ToOptionalIntOrNilIfEmpty(f int) *int

ToOptionalIntOrNilIfEmpty returns a pointer to an int unless it is empty and in that case returns nil.

func ToOptionalOrNilIfEmpty

func ToOptionalOrNilIfEmpty[T any](v T) *T

ToOptionalOrNilIfEmpty returns a pointer to the given field value unless it is empty and in that case returns nil.

func ToOptionalString

func ToOptionalString(s string) *string

ToOptionalString returns a pointer to a string.

func ToOptionalStringOrNilIfEmpty

func ToOptionalStringOrNilIfEmpty(f string) *string

ToOptionalStringOrNilIfEmpty returns a pointer to a string unless it is empty and in that case returns nil.

func ToOptionalStringOrNilIfEmptyf

func ToOptionalStringOrNilIfEmptyf(format string, a ...any) *string

ToOptionalStringOrNilIfEmptyf returns a pointer to a string formatted according to a format specifier unless it is empty and in that case returns nil.

func ToOptionalStringf

func ToOptionalStringf(format string, a ...any) *string

ToOptionalStringf returns a pointer to a string formatted according to a format specifier.

func ToOptionalTime

func ToOptionalTime(f time.Time) *time.Time

ToOptionalTime returns a pointer to a Time.

func ToOptionalTimeOrNilIfEmpty

func ToOptionalTimeOrNilIfEmpty(f time.Time) *time.Time

ToOptionalTimeOrNilIfEmpty returns a pointer to a time unless it is empty and in that case returns nil.

func ToOptionalUint

func ToOptionalUint(f uint) *uint

ToOptionalUint returns a pointer to an uint

func ToOptionalUint32

func ToOptionalUint32(f uint32) *uint32

ToOptionalUint32 returns a pointer to an uint32.

func ToOptionalUint32OrNilIfEmpty

func ToOptionalUint32OrNilIfEmpty(f uint32) *uint32

ToOptionalUint32OrNilIfEmpty returns a pointer to an Uint32 unless it is empty and in that case returns nil.

func ToOptionalUint64

func ToOptionalUint64(f uint64) *uint64

ToOptionalUint64 returns a pointer to an uint64.

func ToOptionalUint64OrNilIfEmpty

func ToOptionalUint64OrNilIfEmpty(f uint64) *uint64

ToOptionalUint64OrNilIfEmpty returns a pointer to an Uint64 unless it is empty and in that case returns nil.

func ToOptionalUintOrNilIfEmpty

func ToOptionalUintOrNilIfEmpty(f uint) *uint

ToOptionalUintOrNilIfEmpty returns a pointer to a Uint unless it is empty and in that case returns nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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