utils

package
v0.0.0-...-5004fd2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExists

func FileExists(name string) bool

func FilterSlice

func FilterSlice[T any](from []T, f func(T) bool) []T

func IsTimeNotNilOrZero

func IsTimeNotNilOrZero(t *time.Time) bool

func IsUUIDInRange

func IsUUIDInRange(id, start, end uuid.UUID) bool

test if uuid is in range [start, end], inclusive

func IsUUIDNil

func IsUUIDNil(id uuid.UUID) bool

in case uuid.Nil is altered

func MapSlice

func MapSlice[T any, U any](from []U, mapFunc MapFunc[T, U]) []T

func MapSliceWithError

func MapSliceWithError[T any, U any](from []U, mapFunc MapFuncWithError[T, U]) ([]T, error)

func NilIfZeroLen

func NilIfZeroLen[T any](s []T) []T

func NilToDefault

func NilToDefault[D any](ptr *D) (v D)

func NonNilUUID

func NonNilUUID(id *uuid.UUID) (uuid.UUID, bool)

func PagerToSlice

func PagerToSlice[T any](pager ItemsPager[T]) (items []T, err error)

func ReadJsonFile

func ReadJsonFile[T any](filename string, target T) error

func SymlinkExists

func SymlinkExists(name string) bool

func ToMapFunc

func ToMapFunc[T any, K comparable](s []T, keyFunc func(item T) K) map[K]T

func ToPtr

func ToPtr[D any](v D) *D

func ToValueMapFunc

func ToValueMapFunc[T any, K comparable, U any](s []T, keyValueFunc func(item T) (K, U)) map[K]U

Types

type CertificateFingerprintSHA1

type CertificateFingerprintSHA1 [sha1.Size]byte

func (*CertificateFingerprintSHA1) HexString

func (s *CertificateFingerprintSHA1) HexString() string

func (CertificateFingerprintSHA1) MarshalText

func (s CertificateFingerprintSHA1) MarshalText() (text []byte, _ error)

func (*CertificateFingerprintSHA1) UnmarshalText

func (s *CertificateFingerprintSHA1) UnmarshalText(text []byte) (err error)

type ItemsPager

type ItemsPager[T any] interface {
	Pager[[]T]
}

func NewChainedItemPagers

func NewChainedItemPagers[T any](pagers ...ItemsPager[T]) ItemsPager[T]

func NewMappedItemsPager

func NewMappedItemsPager[T, U any](from ItemsPager[U], f MapFunc[T, U]) ItemsPager[T]

type MapFunc

type MapFunc[T any, U any] func(U) T

type MapFuncWithError

type MapFuncWithError[T any, U any] func(U) (T, error)

type Nullable

type Nullable[T interface{}] struct {
	HasValue bool
	Value    T
}

type Pager

type Pager[T any] interface {
	More() bool
	NextPage() (page T, err error)
}

func NewMappedPager

func NewMappedPager[T any, U any](from Pager[U], mapFunc MapFunc[T, U]) Pager[T]

func NewPagerWithContext

func NewPagerWithContext[T any](pager PagerRequireContext[T], ctx context.Context) Pager[T]

type PagerRequireContext

type PagerRequireContext[T any] interface {
	More() bool
	NextPage(context.Context) (page T, err error)
}

type PagerWithContext

type PagerWithContext[T any] struct {
	// contains filtered or unexported fields
}

func (*PagerWithContext[T]) More

func (p *PagerWithContext[T]) More() bool

func (*PagerWithContext[T]) NextPage

func (p *PagerWithContext[T]) NextPage() (page T, err error)

type SerializableItemsPager

type SerializableItemsPager[T any] struct {
	ItemsPager[T]
}

func NewSerializableItemsPager

func NewSerializableItemsPager[T any](pager ItemsPager[T]) *SerializableItemsPager[T]

func (*SerializableItemsPager[T]) MarshalJSON

func (p *SerializableItemsPager[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type Set

type Set[D comparable] map[D]bool

func NewSet

func NewSet[D comparable](items ...D) Set[D]

func (Set[D]) Add

func (s Set[D]) Add(item D)

func (Set[D]) Contains

func (s Set[D]) Contains(item D) bool

func (Set[D]) Intersection

func (s Set[D]) Intersection(other Set[D]) Set[D]

func (Set[D]) Items

func (s Set[D]) Items() []D

func (Set[D]) Remove

func (s Set[D]) Remove(item D)

func (Set[D]) Size

func (s Set[D]) Size() int

func (Set[D]) Union

func (s Set[D]) Union(other Set[D]) Set[D]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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