Documentation
¶
Index ¶
- Constants
- Variables
- func AppendUnique[T comparable](slice []T, values ...T) []T
- func ArrayIntersect[T comparable](target []T, destination []T) (intersect []T, removedTargets int32)
- func BeforeString(source string, substr string) string
- func Blue(v interface{}) string
- func CheckBracers(source string, stack Stack[byte]) error
- func CheckTypeOf(value []byte) (isUint, isInt, isFloat, isBool, isString bool)
- func Convert[S, T any](source S) T
- func Cyan(v interface{}) string
- func Each[S any](s []S, callback func(S))
- func ExistsInArray[T comparable](value T, slice []T) bool
- func Filter[S any](s []S, callback func(S) bool) []S
- func GetRndDateTime() time.Time
- func GetRndId() int
- func GetRndNumber(min int, max int) int
- func GetRndPhone() int
- func Green(v interface{}) string
- func Implode[T comparable](values []T, sep string) string
- func Index[T comparable](value T, slice []T) int
- func Magenta(v interface{}) string
- func Map[S, D any](s []S, callback func(S) D) []D
- func NewUUID() string
- func Ptr[T any](v T) *T
- func Rainbow(str string, sep rune) string
- func RandString(length int) string
- func Red(v interface{}) string
- func Reduce[S, D any](init D, s []S, callback func(D, S) D) D
- func ToCamelCase(str string, isFirstTitle bool) string
- func ToUnderscore(str string) string
- func Underline(v interface{}) string
- func Unique[T comparable](left []T, right []T) []T
- func UniqueCompare[S comparable](left []S, right []S) (common []S, removed []S, added []S)
- func UniqueLeft[T comparable](left []T, right []T) []T
- func Yellow(v interface{}) string
- type EntityCache
- func (c *EntityCache[E, T]) AddItemIds(id ...E)
- func (c *EntityCache[E, T]) Filter(searchable []E, compare func(item *T) bool) (result []*T)
- func (c *EntityCache[E, T]) GetAll() map[E]*T
- func (c *EntityCache[E, T]) GetEntity(id E) *T
- func (c *EntityCache[E, T]) GetItemIds() []E
- func (c *EntityCache[E, T]) Idle(ctx context.Context) error
- func (c *EntityCache[E, T]) Len() int
- func (c *EntityCache[E, T]) Map(next func(id E, item *T), ordered bool)
- func (c *EntityCache[E, T]) Refresh() error
- func (c *EntityCache[E, T]) RefreshUntilSuccess() error
- func (c *EntityCache[E, T]) Set(entityMap map[E]*T)
- func (c *EntityCache[E, T]) SetCallback(callback RefreshEntityCallback[E, T])
- func (c *EntityCache[E, T]) SetEntity(id E, item *T)
- func (c *EntityCache[E, T]) SetItemIds(id ...E)
- func (c *EntityCache[E, T]) SortOrder(s func(a, b *T) bool) []E
- func (c *EntityCache[E, T]) UnSetEntity(id E)
- func (c *EntityCache[E, T]) UnSetItemIds(ids ...E)
- type Iterator
- type Pipe
- type PipeArguments
- type PipeInstruction
- type PipeLine
- func (s *PipeLine) Add(instruction PipeInstruction, args ...any)
- func (s *PipeLine) Current(instruction PipeInstruction, args ...any)
- func (s *PipeLine) Deserialize(buf *bytes.Buffer) error
- func (s *PipeLine) Items() []Pipe
- func (s *PipeLine) Reset()
- func (s *PipeLine) Serialize(buf *bytes.Buffer) ([]byte, error)
- type RefreshEntityCallback
- type Stack
- type Tree
- func (t *Tree[T]) FirstChild() *Tree[T]
- func (t *Tree[T]) GetById(id int) *Tree[T]
- func (t *Tree[T]) LastChild() *Tree[T]
- func (t *Tree[T]) Lookup(found func(i *Tree[T]) bool) TreeList[T]
- func (t *Tree[T]) Map(c func(i *Tree[T]))
- func (t *Tree[T]) Path(delimiter string, c func(i *Tree[T]) string) string
- func (t *Tree[T]) UnmarshalJSON(data []byte) error
- type TreeList
- type UUID
Constants ¶
const ( AnsiReset = "\x1b[0m" AnsiBlack = "\x1b[30;1m" AnsiRed = "\x1b[31;1m" AnsiGreen = "\x1b[32;1m" AnsiYellow = "\x1b[33;1m" AnsiBlue = "\x1b[34;1m" AnsiMagenta = "\x1b[35;1m" AnsiCyan = "\x1b[36;1m" AnsiWhite = "\x1b[37;1m" AnsiCustom = "\x1b[38;5;%vm" AnsiCustomCode = "\x1b[38;5;" AnsiBackgroundBlack = "\x1b[40;1m" AnsiBackgroundRed = "\x1b[42;1m" AnsiBackgroundGreen = "\x1b[42;1m" AnsiBackgroundYellow = "\x1b[43;1m" AnsiBackgroundBlue = "\x1b[44;1m" AnsiBackgroundMagenta = "\x1b[45;1m" AnsiBackgroundCyan = "\x1b[46;1m" AnsiBackgroundWhite = "\x1b[47;1m" AnsiBackgroundCustom = "\x1b[48;5;%vm" AnsiBold = "\x1b[1m" AnsiUnderline = "\x1b[4m" AnsiReversed = "\x1b[7m" AnsiCursorUp = "\x1b[%vA" AnsiCursorDown = "\x1b[%vB" AnsiCursorRight = "\x1b[%vC" AnsiCursorLeft = "\x1b[%vD" )
const Charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
Variables ¶
var ( // AnsiRainbowCodes color code for rainbow words // 1 - red // 208 - orange // 11 - yellow // 40 - green // 45 - blue // 27 - blue // 93 - purple AnsiRainbowCodes = []string{"1", "208", "11", "40", "45", "27", "93"} )
Functions ¶
func AppendUnique ¶ added in v1.0.0
func AppendUnique[T comparable](slice []T, values ...T) []T
AppendUnique append unique value to array
func ArrayIntersect ¶ added in v1.0.0
func ArrayIntersect[T comparable](target []T, destination []T) (intersect []T, removedTargets int32)
ArrayIntersect shows duplicated elements in both slices
func BeforeString ¶
BeforeString get string in source before substring
func CheckBracers ¶ added in v1.1.2
CheckBracers check if bracers are correct
func CheckTypeOf ¶ added in v1.6.2
CheckTypeOf check value for type 00001111 - 1 - uint - 2 - int - 4 - float - 8 - string
func Convert ¶ added in v1.1.1
func Convert[S, T any](source S) T
Convert unsafe convert. Use carefully
func Each ¶ added in v1.0.0
func Each[S any](s []S, callback func(S))
Each iterate thought []S and apply on each item collback
func ExistsInArray ¶ added in v1.0.0
func ExistsInArray[T comparable](value T, slice []T) bool
ExistsInArray Check if item exists in slice
func GetRndDateTime ¶
func GetRndNumber ¶
func GetRndPhone ¶
func GetRndPhone() int
func Implode ¶
func Implode[T comparable](values []T, sep string) string
Implode join values via separator
func Index ¶ added in v1.0.0
func Index[T comparable](value T, slice []T) int
Index return index of item if exists. -1 if not
func Map ¶ added in v1.0.0
func Map[S, D any](s []S, callback func(S) D) []D
Map argument source and result destination
func Rainbow ¶ added in v1.0.0
Rainbow crete rainbow string str - string for transformation sep - string separator
func Reduce ¶ added in v1.0.0
func Reduce[S, D any](init D, s []S, callback func(D, S) D) D
Reduce implementation
func ToCamelCase ¶
ToCamelCase transform to camelCase
func ToUnderscore ¶
ToUnderscore transform string to underscore case
func Underline ¶ added in v1.0.0
func Underline(v interface{}) string
Underline wrap into underline text
func Unique ¶ added in v1.0.0
func Unique[T comparable](left []T, right []T) []T
Unique create unique slice between left and right slices
func UniqueCompare ¶ added in v1.7.1
func UniqueCompare[S comparable](left []S, right []S) (common []S, removed []S, added []S)
UniqueCompare Unique compare unique values between arrays
func UniqueLeft ¶ added in v1.0.0
func UniqueLeft[T comparable](left []T, right []T) []T
UniqueLeft create unique slice from left and right slices
Types ¶
type EntityCache ¶ added in v1.4.0
type EntityCache[E comparable, T any] struct { // contains filtered or unexported fields }
EntityCache entity data cache
func NewEntityCache ¶ added in v1.4.0
func NewEntityCache[E comparable, T any](refreshPeriod, maxFailedCount uint16, callback RefreshEntityCallback[E, T], id ...E) *EntityCache[E, T]
NewEntityCache create new entity cache E - identifier type T - type of entity cache refreshPeriod - how often will be refresh executed callback - refresh function
func (*EntityCache[E, T]) AddItemIds ¶ added in v1.4.0
func (c *EntityCache[E, T]) AddItemIds(id ...E)
AddItemIds add entity ids for refresh
func (*EntityCache[E, T]) Filter ¶ added in v1.7.0
func (c *EntityCache[E, T]) Filter(searchable []E, compare func(item *T) bool) (result []*T)
Filter items thread safe searchable - list of ids to iteration. if len(searchable) == 0 then iteration over entityMap compare - is item satisfies for search condition result - list of resulted items
func (*EntityCache[E, T]) GetAll ¶ added in v1.4.0
func (c *EntityCache[E, T]) GetAll() map[E]*T
GetAll get all items
func (*EntityCache[E, T]) GetEntity ¶ added in v1.4.0
func (c *EntityCache[E, T]) GetEntity(id E) *T
GetEntity get single entity
func (*EntityCache[E, T]) GetItemIds ¶ added in v1.4.0
func (c *EntityCache[E, T]) GetItemIds() []E
GetItemIds get refresh entity ids
func (*EntityCache[E, T]) Idle ¶ added in v1.4.0
func (c *EntityCache[E, T]) Idle(ctx context.Context) error
Idle wait for next time refresh event
func (*EntityCache[E, T]) Len ¶ added in v1.4.1
func (c *EntityCache[E, T]) Len() int
Len return len of entity map
func (*EntityCache[E, T]) Map ¶ added in v1.6.0
func (c *EntityCache[E, T]) Map(next func(id E, item *T), ordered bool)
Map iterator through cache items next - single item callback iterator ordered - means that ids define order for item iterations
func (*EntityCache[E, T]) Refresh ¶ added in v1.4.0
func (c *EntityCache[E, T]) Refresh() error
Refresh cache function
func (*EntityCache[E, T]) RefreshUntilSuccess ¶ added in v1.6.1
func (c *EntityCache[E, T]) RefreshUntilSuccess() error
RefreshUntilSuccess refresh until c.maxFailedCount
func (*EntityCache[E, T]) Set ¶ added in v1.4.0
func (c *EntityCache[E, T]) Set(entityMap map[E]*T)
Set entity map
func (*EntityCache[E, T]) SetCallback ¶ added in v1.4.0
func (c *EntityCache[E, T]) SetCallback(callback RefreshEntityCallback[E, T])
SetCallback set refresh callback in case when nil cache will be not refreshed
func (*EntityCache[E, T]) SetEntity ¶ added in v1.4.1
func (c *EntityCache[E, T]) SetEntity(id E, item *T)
SetEntity set single entity
func (*EntityCache[E, T]) SetItemIds ¶ added in v1.4.0
func (c *EntityCache[E, T]) SetItemIds(id ...E)
SetItemIds set entity ids for refresh
func (*EntityCache[E, T]) SortOrder ¶ added in v1.4.0
func (c *EntityCache[E, T]) SortOrder(s func(a, b *T) bool) []E
SortOrder get items sort order according to sort func
func (*EntityCache[E, T]) UnSetEntity ¶ added in v1.5.1
func (c *EntityCache[E, T]) UnSetEntity(id E)
UnSetEntity unset single entity
func (*EntityCache[E, T]) UnSetItemIds ¶ added in v1.5.1
func (c *EntityCache[E, T]) UnSetItemIds(ids ...E)
UnSetItemIds unset item ids
type Iterator ¶ added in v1.0.0
type Iterator struct {
// contains filtered or unexported fields
}
Iterator struct
func NewIterator ¶ added in v1.0.0
NewIterator Iterator constructor
type Pipe ¶ added in v1.5.0
type Pipe struct {
// Instruction for call
Instruction PipeInstruction
// argument for call
Arguments []PipeArguments
}
Pipe single call
func (*Pipe) Push ¶ added in v1.5.0
func (d *Pipe) Push(instruction PipeInstruction, args ...any)
Push Instruction to pipeline with arguments
type PipeInstruction ¶ added in v1.5.0
type PipeInstruction []byte
PipeInstruction Instruction declaration
type PipeLine ¶ added in v1.5.0
type PipeLine struct {
// contains filtered or unexported fields
}
PipeLine collected pipe items
func NewPipeLine ¶ added in v1.5.0
NewPipeLine Create new pipeline with arguments lenI len of instruction field lenA len of arguments list
func (*PipeLine) Add ¶ added in v1.5.0
func (s *PipeLine) Add(instruction PipeInstruction, args ...any)
Add save new call
func (*PipeLine) Current ¶ added in v1.5.0
func (s *PipeLine) Current(instruction PipeInstruction, args ...any)
Current save into current call
func (*PipeLine) Deserialize ¶ added in v1.5.0
Deserialize pipeline
type RefreshEntityCallback ¶ added in v1.4.0
type RefreshEntityCallback[E comparable, T any] func(id ...E) (map[E]*T, error)
RefreshEntityCallback refresh entity callback
type Tree ¶ added in v1.3.0
type Tree[T any] struct { // Identifier Id int `json:"id"` // Parent item Parent *Tree[T] `json:"-"` // Specific tree data Data *T `json:"data"` // Children Children TreeList[T] `json:"children"` }
Tree simple tree
func (*Tree[T]) FirstChild ¶ added in v1.3.0
FirstChild get first child
func (*Tree[T]) UnmarshalJSON ¶ added in v1.3.0
UnmarshalJSON unmarshal data with parents
type TreeList ¶ added in v1.3.0
TreeList list of tree items