gogenutils

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: EUPL-1.2 Imports: 9 Imported by: 4

README

gogenutils

General utility functions for go (as a go package)

Documentation

Index

Constants

View Source
const Version = "v0.5.0"

Version exposes the current package version.

Variables

This section is empty.

Functions

func ByteCountSI

func ByteCountSI(b uint64) string

from https://yourbasic.org/golang/formatting-byte-size-to-human-readable-format/ ByteCountSI returns the "human readable" number of bytes in SI units (as a string)

func FilterCommonRootDirs

func FilterCommonRootDirs(strSlice []string) []string

FilterCommonRootDirs recursively filters out paths for which any higher root path exists in the same slice

func FilterSlicePfxStr

func FilterSlicePfxStr(s []string) []string

FilterSlicePfxStr filters out all string items of which another slice member is a prefix, recursively by convention take the first element as the "pivot"

func InSlice deprecated

func InSlice[E comparable](item E, slice []E) bool

InSlice returns true if item is in slice and false otherwise.

Deprecated: use the standard library slices.Contains(slice, item) directly. This is now a thin generic wrapper; callers should be migrated.

func InSliceGlob added in v0.5.0

func InSliceGlob(checkpath string, matchglobs []string, caseSensitive bool) bool

InSliceGlob reports whether checkpath matches any of the glob patterns in matchglobs (using filepath.Match semantics). When caseSensitive is false, both the path and the patterns are lower-cased before matching. Typically callers pass filepath.Base(path) as checkpath.

func PosInSlice deprecated

func PosInSlice[E comparable](item E, slice []E) int

PosInSlice returns the position of item in slice or -1 if not found.

Deprecated: use the standard library slices.Index(slice, item) directly. This is now a thin generic wrapper; callers should be migrated.

func RemoveFromStringSlice deprecated

func RemoveFromStringSlice(item string, slice []string) []string

RemoveFromStringSlice removes the first occurrence of item and returns the resulting slice. If item is not present the original slice is returned.

Deprecated: use slices.Delete together with slices.Index (or slices.DeleteFunc) directly. This is now a thin wrapper; callers should be migrated. Note that, like slices.Delete, this modifies the backing array of the input slice.

func SlicesEqual deprecated

func SlicesEqual[E comparable](a, b []E) bool

SlicesEqual tells whether a and b contain the same elements in the same order.

Deprecated: use the standard library slices.Equal(a, b) directly. This is now a thin generic wrapper; callers should be migrated.

func StringSliceUniq added in v0.5.0

func StringSliceUniq(sslice *[]string) *[]string

func TypedSlice added in v0.5.0

func TypedSlice[Telem any](s []interface{}) (ret []Telem)

func WriteToYaml

func WriteToYaml(filePath string, object interface{}, perm fs.FileMode) error

WriteToYaml writes given object to yaml

Types

type Errors

type Errors struct {
	// contains filtered or unexported fields
}

func NewErrors

func NewErrors() *Errors

func (*Errors) AddIf

func (e *Errors) AddIf(err error) error

func (*Errors) AddMsgf

func (e *Errors) AddMsgf(format string, param ...interface{}) error

func (*Errors) AddMsgs

func (e *Errors) AddMsgs(message ...string)

func (*Errors) Append added in v0.4.0

func (e *Errors) Append(errs *Errors) *Errors

func (*Errors) Err

func (e *Errors) Err() error

func (*Errors) ErrString

func (e *Errors) ErrString() string

func (*Errors) ErrStrings

func (e *Errors) ErrStrings() []string

type Map added in v0.5.0

type Map[Tkey comparable, Telem any] map[Tkey]Telem

func NewMap added in v0.5.0

func NewMap[Tkey comparable, Telem any]() Map[Tkey, Telem]

func (Map[Tkey, Telem]) AttrSlice added in v0.5.0

func (m Map[Tkey, Telem]) AttrSlice(selfun func(Telem) any) (rslice []any)

AttrSlice is used to get a slice of attributes of Telem that are selected into a user-provided struct using the provided function Unfortunately we cannot use generics in the function parameter, so we are stuck with the any return type, which is the same as interface{} Therefore this function returns []interface{} which we must convert. As a workaround we now do this conversion generic static function TypedSlice. More info here? (But behind paywall) https://itnext.io/generic-map-filter-and-reduce-in-go-3845781a591c

func (Map[Tkey, Telem]) FilterMapByKey added in v0.5.0

func (m Map[Tkey, Telem]) FilterMapByKey(cmpfun func(Tkey) bool) (filteredMap Map[Tkey, Telem])

func (Map[Tkey, Telem]) FilterMapByVal added in v0.5.0

func (m Map[Tkey, Telem]) FilterMapByVal(cmpfun func(Telem) bool) (filteredMap Map[Tkey, Telem])

func (Map[Tkey, Telem]) FilterMapToSlice added in v0.5.0

func (m Map[Tkey, Telem]) FilterMapToSlice(cmpfun func(Telem) bool) (filteredSlice []Telem)

we could use MapToSlice, but that would mean two loops...

func (*Map[Tkey, Telem]) ToSlice added in v0.5.0

func (m *Map[Tkey, Telem]) ToSlice() (rslice []Telem)

type TSimpleSLQ

type TSimpleSLQ struct {
	// contains filtered or unexported fields
}

func NewSimpleSLQ

func NewSimpleSLQ() *TSimpleSLQ

NewSimpleSLQ contsructor SimpleSLQ is a experimental, generic "Slice/List/Queue" hybrid like structure based on slice that implements:

Pop/Push, Next/Prev, IndexOf, ...

func (*TSimpleSLQ) Append

func (s *TSimpleSLQ) Append(item interface{}) interface{}

func (*TSimpleSLQ) Contains

func (s *TSimpleSLQ) Contains(item interface{}) bool

func (*TSimpleSLQ) CurrentItem

func (s *TSimpleSLQ) CurrentItem() interface{}

func (*TSimpleSLQ) IndexOf

func (s *TSimpleSLQ) IndexOf(item interface{}) int

func (*TSimpleSLQ) InsertAt

func (s *TSimpleSLQ) InsertAt(item interface{}, pos int) interface{}

func (*TSimpleSLQ) ItemAt

func (s *TSimpleSLQ) ItemAt(pos int) interface{}

func (*TSimpleSLQ) Length

func (s *TSimpleSLQ) Length() int

func (*TSimpleSLQ) Next

func (s *TSimpleSLQ) Next() bool

func (*TSimpleSLQ) Pop

func (s *TSimpleSLQ) Pop() interface{}

func (*TSimpleSLQ) Prev

func (s *TSimpleSLQ) Prev() bool

func (*TSimpleSLQ) Push

func (s *TSimpleSLQ) Push(item interface{}) interface{}

Jump to

Keyboard shortcuts

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