util

package
v0.0.0-...-d50b6f3 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const PlatformTag = "lnx"

Variables

View Source
var (
	ErrNoTimer = errors.New("Timer is nil")
)

Functions

func CamelCase

func CamelCase(in string) (out string)

func Env

func Env(name string, ptr interface{}, tag string, def interface{}, usage string)

Env works similar to 'flag', but overrides the default value with env variable (name) if present.

TODO: So far, we only care about bool, int and string. float64 and 'big-ints' not currently implemented.

func Eval

func Eval(in interface{}, fnc func(*TaggedValue) error) (err error)

func Exec

func Exec(cmd string) (out []byte, err error)

func Id0Hash

func Id0Hash() string

Id0Hash attempts to get the first available UUID from /dev/disk/by-uuid. If this fails, use MacAddr() as input. Returns an MD5 hash of either result.

func IsFile

func IsFile(path string, in ...int) (ok bool)

IsFile checks if file (path) exists, and is a Regular file. Will recurse on symlinks to a max depth of 10

func MacAddr

func MacAddr() (addr string)

MacAddr gets the MAC hardware address of 1st (non-loopback) interface the host machine

func MacHash

func MacHash() string

func NewWorkPool

func NewWorkPool(options ...Options) *workPool

NewWorkPool instantiates and returns a WorkPool with (optional) parameters

func PlatformVersion

func PlatformVersion() (out string)

func UnderScore

func UnderScore(in string) string

func Units

func Units(in interface{}) string

func YamlRead

func YamlRead(path string, in interface{}) error

func YamlWrite

func YamlWrite(path string, in interface{}) error

Types

type BsonTag

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

func (*BsonTag) Convert

func (t *BsonTag) Convert() bool

func (*BsonTag) Ignore

func (t *BsonTag) Ignore() bool

func (*BsonTag) Key

func (t *BsonTag) Key() bool

func (*BsonTag) Name

func (t *BsonTag) Name() string

func (*BsonTag) Null

func (t *BsonTag) Null() bool

func (*BsonTag) Primary

func (t *BsonTag) Primary() bool

func (*BsonTag) Ref

func (t *BsonTag) Ref() *KeyRef

type Collection

type Collection interface {
	Add(...interface{})
	Remove(...interface{})
	Has(...interface{})
	List([]interface{})
	Reset()
	Size() int
}

type Fifo

type Fifo[T any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

fifo queue

func NewFifo

func NewFifo[T any]() *Fifo[T]

NewFifo creates a new and empty FIFO queue

func (*Fifo[T]) Add

func (q *Fifo[T]) Add(item T)

Add an item to the end of the queue

func (*Fifo[T]) Len

func (q *Fifo[T]) Len() (l int)

Return the number of queued items

func (*Fifo[T]) Next

func (q *Fifo[T]) Next() (item T)

Remove the item at the head of the queue and return it. Returns nil when there are no items left in queue.

type Host

type Host interface {
	IpAddr() (string, error)
	InstId() (string, error)
}

func NewHost

func NewHost(tag string) (Host, error)

type JsonTag

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

func (*JsonTag) Convert

func (t *JsonTag) Convert() bool

func (*JsonTag) Ignore

func (t *JsonTag) Ignore() bool

func (*JsonTag) Key

func (t *JsonTag) Key() bool

func (*JsonTag) Name

func (t *JsonTag) Name() string

func (*JsonTag) Null

func (t *JsonTag) Null() bool

func (*JsonTag) Primary

func (t *JsonTag) Primary() bool

func (*JsonTag) Ref

func (t *JsonTag) Ref() *KeyRef

type KeyRef

type KeyRef struct {
	T string
	C string
}

func (*KeyRef) String

func (k *KeyRef) String() string

type LoadAvg

type LoadAvg []float64

func GetLoadAvg

func GetLoadAvg() (LoadAvg, error)

func (LoadAvg) String

func (ld LoadAvg) String() string

type Md5Sum

type Md5Sum []byte

func Md5

func Md5(in ...any) Md5Sum

func Md5Copy

func Md5Copy(dst io.Writer, src io.Reader) (sum Md5Sum, written int64, err error)

func (Md5Sum) Equal

func (m Md5Sum) Equal(c Md5Sum) bool

func (Md5Sum) String

func (m Md5Sum) String() string

func (Md5Sum) Valid

func (m Md5Sum) Valid() bool

type Node

type Node interface{}

type Option

type Option any

Option entry

type Options

type Options map[string]Option

Options map of Option

func (Options) Get

func (o Options) Get(k string) (v Option, ok bool)

func (Options) GetInt

func (o Options) GetInt(k string) (i int, ok bool)

func (Options) GetStr

func (o Options) GetStr(k string) (s string, ok bool)

func (Options) Has

func (o Options) Has(keys ...string) (res []string, ok bool)

type PoolWorker

type PoolWorker interface {
	Run()
}

PoolWorker defines the implementing workers

type Queue

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

Queue is a basic FIFO queue based on a circular list that resizes as needed.

func NewQueue

func NewQueue(size int) *Queue

NewQueue returns a new queue with the given initial size.

func (*Queue) Len

func (q *Queue) Len() int

func (*Queue) Pop

func (q *Queue) Pop() Node

Pop removes and returns a node from the queue in first to last order.

func (*Queue) Push

func (q *Queue) Push(n Node)

Push adds a node to the queue.

type Range

type Range interface {
	Tag() string
	Span() *Span
	Spans() []*Span
	IsEmpty() bool
	String() string
}

func NewRange

func NewRange(key string, vs ...interface{}) (rng Range, err error)

type RangeRequest

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

func (*RangeRequest) Add

func (r *RangeRequest) Add(s *Span)

func (*RangeRequest) IsEmpty

func (r *RangeRequest) IsEmpty() bool

func (*RangeRequest) Span

func (r *RangeRequest) Span() *Span

func (*RangeRequest) Spans

func (r *RangeRequest) Spans() []*Span

func (*RangeRequest) String

func (r *RangeRequest) String() (rs string)

func (*RangeRequest) Tag

func (r *RangeRequest) Tag() string

type RangeResponse

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

func (*RangeResponse) Add

func (r *RangeResponse) Add(s *Span)

func (*RangeResponse) IsEmpty

func (r *RangeResponse) IsEmpty() bool

func (*RangeResponse) Span

func (r *RangeResponse) Span() *Span

func (*RangeResponse) Spans

func (r *RangeResponse) Spans() []*Span

func (*RangeResponse) String

func (r *RangeResponse) String() (rs string)

func (*RangeResponse) Tag

func (r *RangeResponse) Tag() string

type Set

type Set struct {
	sync.Map
}

func NewSet

func NewSet(in ...interface{}) *Set

func (*Set) Add

func (s *Set) Add(in ...interface{})

func (*Set) Has

func (s *Set) Has(in ...interface{}) bool

func (*Set) List

func (s *Set) List() (out []interface{})

func (*Set) Remove

func (s *Set) Remove(in ...interface{})

func (*Set) Reset

func (s *Set) Reset()

func (*Set) Size

func (s *Set) Size() (n int)

type Sha1Sum

type Sha1Sum []byte

func Sha1

func Sha1(in interface{}) Sha1Sum

func Sha1Copy

func Sha1Copy(dst io.Writer, src io.Reader) (sum Sha1Sum, written int64, err error)

func (Sha1Sum) Equal

func (s Sha1Sum) Equal(c Md5Sum) bool

func (Sha1Sum) String

func (s Sha1Sum) String() string

func (Sha1Sum) Valid

func (s Sha1Sum) Valid() bool

type Span

type Span struct {
	Min,
	Max int64
}

func (*Span) Len

func (s *Span) Len() int64

func (*Span) String

func (s *Span) String() (ss string)

type SqlTag

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

func (*SqlTag) Convert

func (t *SqlTag) Convert() bool

func (*SqlTag) Ignore

func (t *SqlTag) Ignore() bool

func (*SqlTag) Key

func (t *SqlTag) Key() bool

func (*SqlTag) Name

func (t *SqlTag) Name() string

func (*SqlTag) Null

func (t *SqlTag) Null() bool

func (*SqlTag) Primary

func (t *SqlTag) Primary() bool

func (*SqlTag) Ref

func (t *SqlTag) Ref() *KeyRef

type Stack

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

Stack is a basic LIFO stack that resizes as needed.

func NewStack

func NewStack() *Stack

NewStack returns a new stack.

func (*Stack) Len

func (s *Stack) Len() int

func (*Stack) Peek

func (s *Stack) Peek() Node

Peek returns the top node on the stack (if any).

func (*Stack) Pop

func (s *Stack) Pop() Node

Pop removes and returns a node from the stack in last to first order.

func (*Stack) Push

func (s *Stack) Push(n Node)

Push adds a node to the stack.

type Tag

type Tag interface {
	Name() string
	Convert() bool
	Ignore() bool
	Null() bool
	Key() bool
	Primary() bool
	Ref() *KeyRef
}

func TagOf

func TagOf(f reflect.StructField) (out Tag)

type TagMap

type TagMap map[string]interface{}

type TagOption

type TagOption uint
const (
	Ignore TagOption = (1 << iota)
	Convert
	Nullable
	Key
	Primary
)

type TaggedValue

type TaggedValue struct {
	Value
	T Tag
	F reflect.StructField
	A interface{}
}

type Template

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

func NewTemplate

func NewTemplate(text string, tags TagMap) *Template

func (*Template) Add

func (t *Template) Add(m TagMap) *Template

func (*Template) Bytes

func (t *Template) Bytes() (out []byte)

func (*Template) Parse

func (t *Template) Parse() (out []byte, err error)

func (*Template) String

func (t *Template) String() (out string)

type Timer

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

func NewTimer

func NewTimer(name string, d time.Duration, fnc func(time.Time)) *Timer

func (*Timer) Start

func (t *Timer) Start() *Timer

func (*Timer) Stop

func (t *Timer) Stop()

type Value

type Value struct {
	K string
	V interface{}
}

type Values

type Values map[string]interface{}

func (Values) ForEach

func (vs Values) ForEach(fnc func(k string, v any) bool)

func (Values) List

func (vs Values) List() (list []*Value)

type WorkPool

type WorkPool interface {
	Submit(w PoolWorker) error
}

WorkPool holds the Queue and Worker channels

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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