utils

package
v0.0.0-...-8495beb Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deref

func Deref[T any](t *T) T

func FormatISO

func FormatISO(t time.Time) string

func Must

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

func OptionalElsePtr

func OptionalElsePtr[T, R any](o optional.Optional[T], fn func(T) R) *R

func OptionalID

func OptionalID(id xid.ID) *xid.ID

OptionalID is a special helper only used for tests where the seed data must set IDs for resources by calling `WithID`. In this case, the ID must be set using Ent's `SetNillableID` builder method. This function works by taking a a pointer to an ID and only setting it if the pointer is not nil. The problem with this is that all resource structs use IDs as values, not pointers so in order to derive a pointer that may or may not be nil, this function simply checks if the xid is considered "valid" and if it isn't, simply returns nil.

func OptionalPointer

func OptionalPointer[T Zeroable](t T) optional.Optional[T]

func OptionalSlice

func OptionalSlice[T any](t []T) optional.Optional[[]T]

func OptionalToPointer

func OptionalToPointer[T any](o optional.Optional[T]) *T

func OptionalZero

func OptionalZero[T Zeroable](t T) optional.Optional[T]

func Ref

func Ref[T any](t T) *T

func SetIfPresent

func SetIfPresent[T any](m model.Mutation, field string, value optional.Optional[T])

func TestAll

func TestAll[T any](
	t *testing.T,
	implementations []ImplConstructor[T],
	fn func(*testing.T, T),
)

TestAll runs each test for each implementation of some interface.

func ToMap

func ToMap[T any, R any](fn func(t T) R) func(t T) R

ToMap is for use with samber/lo.Map

Types

type ImplConstructor

type ImplConstructor[T any] func() T

type Zeroable

type Zeroable interface {
	IsZero() bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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