util

package
v0.0.0-...-722e3e0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// OutThreshold is the default console log level
	OutThreshold = jww.LevelError

	// LogThreshold is the default log file level
	LogThreshold = jww.LevelWarn
)
View Source
var LogAreaPadding = 6

LogAreaPadding of log areas

Functions

func CaptureLogs

func CaptureLogs(c chan<- Param)

CaptureLogs appends uiWriter to relevant log levels

func DecodeOther

func DecodeOther(other interface{}, cc interface{}) error

DecodeOther uses mapstructure to decode into target structure. Unused keys cause errors.

func DefaultPort

func DefaultPort(conn string, port int) string

DefaultPort appends given port to connection if not specified

func DefaultScheme

func DefaultScheme(uri string, scheme string) string

DefaultScheme prepends given scheme to uri if not specified

func FormatValue

func FormatValue(format string, val interface{}) string

FormatValue will apply specific formatting in addition to standard sprintf

func Getenv

func Getenv(key string, def ...string) string

func LocalIPs

func LocalIPs() (ips []net.IPNet)

LocalIPs returns a slice of local IPv4 addresses

func LogLevel

func LogLevel(defaultLevel string, areaLevels map[string]string)

LogLevel sets log level for all loggers

func LogLevelForArea

func LogLevelForArea(area string) jww.Threshold

LogLevelForArea gets the log level for given log area

func LogLevelToThreshold

func LogLevelToThreshold(level string) jww.Threshold

LogLevelToThreshold converts log level string to a jww Threshold

func Loggers

func Loggers(cb func(string, *Logger))

Loggers invokes callback for each configured logger

func RandomString

func RandomString(n int) string

RandomString creates random string of N integers

func ReplaceFormatted

func ReplaceFormatted(s string, kv map[string]interface{}) (string, error)

ReplaceFormatted replaces all occurrences of ${key} with formatted val from the kv map

func Truish

func Truish(s string) bool

Truish returns true if value is truish (true/1/on)

Types

type Cache

type Cache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Cache is a data store

func NewCache

func NewCache() *Cache

NewCache creates cache

func (*Cache) Add

func (c *Cache) Add(key string, param Param)

Add entry to cache

func (*Cache) All

func (c *Cache) All() []Param

All provides a copy of the cached values

func (*Cache) Get

func (c *Cache) Get(key string) Param

Get entry from cache

func (*Cache) GetChecked

func (c *Cache) GetChecked(id int, key string) (res Param, err error)

GetChecked returns checked value from cache

func (*Cache) Run

func (c *Cache) Run(in <-chan Param)

Run adds input channel's values to cache

func (*Cache) State

func (c *Cache) State() map[string]interface{}

State provides a structured copy of the cached values Loadpoints are aggregated as loadpoints array

type Logger

type Logger struct {
	*jww.Notepad
	// contains filtered or unexported fields
}

Logger wraps a jww notepad to avoid leaking implementation detail

func NewLogger

func NewLogger(area string) *Logger

NewLogger creates a logger with the given log area and adds it to the registry

func (*Logger) Name

func (l *Logger) Name() string

Name returns the loggers name

type Param

type Param struct {
	LoadPoint *int
	Key       string
	Val       interface{}
}

Param is the broadcast channel data type

func (Param) UniqueID

func (p Param) UniqueID() string

UniqueID returns unique identifier for parameter LoadPoint/Key combination

type Tee

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

Tee distributed parameters to subscribers

func (*Tee) Attach

func (t *Tee) Attach() <-chan Param

Attach creates a new receiver channel and attaches it to the tee

func (*Tee) Run

func (t *Tee) Run(in <-chan Param)

Run starts parameter distribution

type TeeAttacher

type TeeAttacher interface {
	Attach() <-chan Param
}

TeeAttacher allows to attach a listener to a tee

type Waiter

type Waiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Waiter provides monitoring of receive timeouts and reception of initial value

func NewWaiter

func NewWaiter(timeout time.Duration, logInitialWait func()) *Waiter

NewWaiter creates new waiter

func (*Waiter) LockWithTimeout

func (p *Waiter) LockWithTimeout() time.Duration

LockWithTimeout waits for initial value and checks if update timeout has elapsed

func (*Waiter) Update

func (p *Waiter) Update()

Update is called when client has received data. Update resets the timeout counter. It is client responsibility to ensure that the waiter is not locked when Update is called.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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