util

package
v0.0.0-...-0c7050d Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 23 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 (
	// RedactReplacement is the default replacement string
	RedactReplacement = "***"

	// RedactHook is the hook for expanding different representations of
	// redaction items. Setting to nil will disable redaction.
	RedactHook = RedactDefaultHook
)
View Source
var ErrStateExpired = fmt.Errorf("state expired")
View Source
var LogAreaPadding = 6

LogAreaPadding of log areas

Functions

func CaptureLogs

func CaptureLogs(c chan<- Param)

CaptureLogs appends uiWriter to relevant log levels for loggers created before uiChan is initialized

func DecodeOther

func DecodeOther(other, 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, scheme string) string

DefaultScheme prepends given scheme to uri if not specified

func Flusher

func Flusher() flush

Flusher returns a new flush channel

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 RedactDefaultHook

func RedactDefaultHook(s string) []string

RedactDefaultHook expands a redaction item to include URL encoding

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 SignFromPower

func SignFromPower(current float64, power float64) float64

SignFromPower is a helper function to create signed current from signed power bypassing already signed current

func Truish

func Truish(s string) bool

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

Types

type AuthCollection

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

func NewAuthCollection

func NewAuthCollection(paramC chan<- Param) *AuthCollection

func (*AuthCollection) Publish

func (ac *AuthCollection) Publish()

publish routes and status

func (*AuthCollection) Register

func (ac *AuthCollection) Register(baseURI, title string) *AuthProvider

type AuthProvider

type AuthProvider struct {
	Uri           string `json:"uri"`
	Authenticated bool   `json:"authenticated"`
	// contains filtered or unexported fields
}

func (*AuthProvider) Handler

func (ap *AuthProvider) Handler() chan<- bool

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) 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 ConfigError

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

ConfigError wraps yaml configuration errors from mapstructure

func (*ConfigError) Error

func (e *ConfigError) Error() string

func (*ConfigError) Unwrap

func (e *ConfigError) Unwrap() error

type Logger

type Logger struct {
	*jww.Notepad
	*Redactor
}

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) Redact

func (l *Logger) Redact(items ...string) *Logger

Redact adds items for redaction

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 Queue

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

Queue is based on https://github.com/golang-ds/queue

func NewQueue

func NewQueue[T any]() *Queue[T]

NewQueue constructs and returns an empty slice-queue.

func (*Queue[T]) Clear

func (q *Queue[T]) Clear()

Clear empties the queue.

func (*Queue[T]) Dequeue

func (q *Queue[T]) Dequeue() (val T, ok bool)

Dequeue removes and returns the front element of the queue. It returns false if the queue was empty.

func (*Queue[T]) Enqueue

func (q *Queue[T]) Enqueue(data T)

Enqueue adds an element to the end of the queue.

func (*Queue[T]) First

func (q *Queue[T]) First() (val T, ok bool)

First returns the front element of the queue. It returns false if the queue was empty.

func (*Queue[T]) IsEmpty

func (q *Queue[T]) IsEmpty() bool

IsEmpty returns true if the queue is empty.

func (*Queue[T]) Size

func (q *Queue[T]) Size() int

Size returns the number of the elements in the queue.

type Redactor

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

Redactor implements a redacting io.Writer

func (*Redactor) Redact

func (l *Redactor) Redact(redact ...string)

Redact adds items for redaction

func (*Redactor) Write

func (l *Redactor) Write(p []byte) (n int, err error)

type State

type State struct {
	Time time.Time
}

func DecryptState

func DecryptState(enc string, key []byte) (*State, error)

func NewState

func NewState() State

func (*State) Encrypt

func (c *State) Encrypt(key []byte) string

func (*State) Validate

func (c *State) Validate() error

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 {
	// 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) Overdue

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

Overdue waits for initial update and returns the duration since the last update in excess of timeout.

func (*Waiter) Update

func (p *Waiter) Update()

Update is called when client has received data. Update resets the timeout counter.

Directories

Path Synopsis
Package goversion should only be used as a blank import.
Package goversion should only be used as a blank import.
Package urlvalues provides functions for working with url.Values
Package urlvalues provides functions for working with url.Values

Jump to

Keyboard shortcuts

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