util

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkArray

func ChunkArray[T any](input []T, chunkSize int) [][]T

func Coalesce

func Coalesce[T any](values ...*T) *T

func CoalesceArray added in v0.2.0

func CoalesceArray[T any, A []T](values ...A) A

func CoalesceWithFunc

func CoalesceWithFunc[T any, PtrT *T](checkFunc CoalesceFunc[PtrT], values ...PtrT) (PtrT, bool)

Returns the first non-nil element that the provided function returns true for

func DeepFindInStruct

func DeepFindInStruct[T interface{}](haystack interface{}) []*T

Must provide a pointer as the haystack See DeepFindInStructAdvanced This version will ignore zero values for structs

func DeepFindInStructAdvanced

func DeepFindInStructAdvanced[T interface{}](haystack interface{}, options *DeepFindInStructOptions) []*T

Must provide a pointer as the haystack

this will recurse into a struct and find all the values of type T within that struct, as well as any child structs

Note: this will stop searching once it finds a match. If you have self-referencing structs, it will not find child structs within a matching struct

func FirstParam

func FirstParam[T any, U any](fp T, _ ...U) T

returns the first value of a multi-return statement

func IsBlank

func IsBlank(str *string) bool

func IsNilable

func IsNilable(v reflect.Value) bool

Returns whether or not a given value could be set to nil

func Jsonify

func Jsonify(val any) (string, error)

Stop encoding < > &. We aren't in a browser

func JsonifyEscaped added in v0.1.0

func JsonifyEscaped(val any) (string, error)

The default way of json marshal, encodes < > &

func JsonifyPretty

func JsonifyPretty(val any) (string, error)

func JsonifyPrettyEscaped added in v0.2.0

func JsonifyPrettyEscaped(val any) (string, error)

func LongestCommonPrefix added in v0.3.0

func LongestCommonPrefix(strs []string) string

https://golangbyexample.com/longest-common-prefix-golang/

func Must

func Must[T any](v T, err error) T

func MustCoalesce

func MustCoalesce[T any](values ...*T) *T

func Ptr

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

func ShouldCoalesce

func ShouldCoalesce[T any](values ...*T) (*T, error)

func StrArrayToInterArray

func StrArrayToInterArray[T ~string](things []T) []interface{}

This is used to allow the AWS Enum string lists to be cast to an array of interfaces used for JSONSchema

func Ternary added in v0.2.0

func Ternary[T any](expr bool, trueVal T, falseVal T) T

Types

type CoalesceFunc

type CoalesceFunc[T any] func(T) bool

type DeepFindInStructOptions

type DeepFindInStructOptions struct {
	// If true, this will return struct VALUE fields that have a zero value for the requested type
	// By default if you have a value field (vs a pointer field), with a zero struct value,
	// it will not be returned as it is assumed to have not been provided
	IncludeZeroStruct bool
}

Jump to

Keyboard shortcuts

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