Documentation
¶
Overview ¶
The Tideland Common Go Library contains a lot of helpful types and functions for many kinds of software. Those are a map/reduce, sorting, caching, time handling, UUIDs, lazy evaluation, chronological jobs, state machines, monitoring, suervision, a simple markup language and much more.
Index ¶
- Constants
- Variables
- func BuildLazyEvaluator(evalFunc EvalFunc, initState interface{}) func() interface{}
- func BuildLazyIntEvaluator(evalFunc EvalFunc, initState interface{}) func() int
- func DayInList(time *time.Time, days []int) bool
- func DayInRange(time *time.Time, minDay, maxDay int) bool
- func Debug(format string, args ...interface{})
- func Dispatch(variable interface{}, name string, args ...interface{}) ([]interface{}, bool)
- func HelpIfNeeded(r Recoverable, err interface{})
- func HourInList(time *time.Time, hours []int) bool
- func HourInRange(time *time.Time, minHour, maxHour int) bool
- func Identifier(parts ...interface{}) string
- func ImAlive(h *Heartbeat)
- func KeyLessFunc(a *KeyValue, b *KeyValue) bool
- func LimitedSepIdentifier(sep string, limit bool, parts ...interface{}) string
- func MinuteInList(time *time.Time, minutes []int) bool
- func MinuteInRange(time *time.Time, minMinute, maxMinute int) bool
- func MonthInList(time *time.Time, months []int) bool
- func MonthInRange(time *time.Time, minMonth, maxMonth int) bool
- func NsDays(count int64) int64
- func NsHours(count int64) int64
- func NsMicroseconds(count int64) int64
- func NsMilliseconds(count int64) int64
- func NsMinutes(count int64) int64
- func NsSeconds(count int64) int64
- func NsWeeks(count int64) int64
- func SecondInList(time *time.Time, seconds []int) bool
- func SecondInRange(time *time.Time, minSecond, maxSecond int) bool
- func SepIdentifier(sep string, parts ...interface{}) string
- func Sort(data sort.Interface)
- func TypeAsIdentifierPart(i interface{}) string
- func WeekdayInList(time *time.Time, weekdays []int) bool
- func WeekdayInRange(time *time.Time, minWeekday, maxWeekday int) bool
- func YearInList(time *time.Time, years []int64) bool
- func YearInRange(time *time.Time, minYear, maxYear int64) bool
- type CachedValue
- type CheckFunc
- type Condition
- type Crontab
- type DynamicStatusRetriever
- type EvalFunc
- type FSM
- func (fsm *FSM) Recover(recoverable Recoverable, err interface{})
- func (fsm *FSM) Send(payload interface{})
- func (fsm *FSM) SendAfter(payload interface{}, ns int64)
- func (fsm *FSM) SendWithResult(payload interface{}) interface{}
- func (fsm *FSM) State() string
- func (fsm *FSM) Supervisor() *Supervisor
- type Handler
- type Hash
- type Hashable
- type Heartbeat
- type Heartbeatable
- type Job
- type KeyValue
- type KeyValueChan
- type KeyValueChans
- type KeyValueLessFunc
- type KeyValues
- func (kv *KeyValues) Add(key string, value interface{})
- func (kv *KeyValues) Append(akv KeyValues)
- func (kv *KeyValues) AppendChan(kvChan KeyValueChan)
- func (kv *KeyValues) KeyValueChan() KeyValueChan
- func (kv *KeyValues) Len() int
- func (kv *KeyValues) Less(i, j int) bool
- func (kv *KeyValues) Sort()
- func (kv *KeyValues) Swap(i, j int)
- type MapFunc
- type Measuring
- type MeasuringPoint
- type Node
- type Processor
- type Recoverable
- type ReduceFunc
- type RetrievalFunc
- type SigChan
- type SmlReader
- type SmlWriterProcessor
- type StaySetVariable
- type Supervisor
- type SystemMonitor
- func (sm *SystemMonitor) BeginMeasuring(id string) *Measuring
- func (sm *SystemMonitor) DynamicStatusValuesDo(f func(string, string))
- func (sm *SystemMonitor) DynamicStatusValuesMap(f func(string, string) interface{}) []interface{}
- func (sm *SystemMonitor) DynamicStatusValuesPrintAll()
- func (sm *SystemMonitor) DynamicStatusValuesWrite(w io.Writer, ff func(string, string) bool)
- func (sm *SystemMonitor) Measure(id string, f func())
- func (sm *SystemMonitor) MeasuringPointsDo(f func(*MeasuringPoint))
- func (sm *SystemMonitor) MeasuringPointsMap(f func(*MeasuringPoint) interface{}) []interface{}
- func (sm *SystemMonitor) MeasuringPointsPrintAll()
- func (sm *SystemMonitor) MeasuringPointsWrite(w io.Writer, ff func(*MeasuringPoint) bool)
- func (sm *SystemMonitor) Recover(recoverable Recoverable, err interface{})
- func (sm *SystemMonitor) Register(id string, rf DynamicStatusRetriever)
- func (sm *SystemMonitor) SetValue(id string, v int64)
- func (sm *SystemMonitor) StaySetVariablesDo(f func(*StaySetVariable))
- func (sm *SystemMonitor) StaySetVariablesMap(f func(*StaySetVariable) interface{}) []interface{}
- func (sm *SystemMonitor) StaySetVariablesPrintAll()
- func (sm *SystemMonitor) StaySetVariablesWrite(w io.Writer, ff func(*StaySetVariable) bool)
- func (sm *SystemMonitor) Supervisor() *Supervisor
- func (sm *SystemMonitor) Unregister(id string)
- type TagNode
- func (tn *TagNode) AppendTag(tag string) *TagNode
- func (tn *TagNode) AppendTagNode(n *TagNode) *TagNode
- func (tn *TagNode) AppendTaggedText(tag, text string) *TagNode
- func (tn *TagNode) AppendText(text string) *TextNode
- func (tn *TagNode) AppendTextNode(n *TextNode) *TextNode
- func (tn *TagNode) Len() int
- func (tn *TagNode) ProcessWith(p Processor)
- func (tn *TagNode) String() string
- type TaskFunc
- type TextNode
- type Timeout
- type UUID
Constants ¶
const ( SIG_STOP = true SIG_RESTART = false )
Signals to stop or restart a cached value.
const RELEASE = "Tideland Common Go Library Release 2011-09-22"
Variables ¶
var QuickSortParallelThreshold int = 4095
Threshold for switching from parallel to sequential quick sort.
var QuickSortSequentialThreshold int = 63
Threshold for switching from sequential quick sort to insertion sort.
Functions ¶
func BuildLazyEvaluator ¶
func BuildLazyEvaluator(evalFunc EvalFunc, initState interface{}) func() interface{}
Generic builder for lazy evaluators.
func BuildLazyIntEvaluator ¶
Builder for lazy evaluators with ints as result.
func DayInRange ¶
Test if a day of a time is in a given range.
func Debug ¶
func Debug(format string, args ...interface{})
Debug prints a debug information to the log with file and line.
func HelpIfNeeded ¶
func HelpIfNeeded(r Recoverable, err interface{})
Tell the supervisor to help if the passed error is not nil.
func HourInList ¶
Test if the hour of a time is in a given list.
func HourInRange ¶
Test if a hour of a time is in a given range.
func Identifier ¶
func Identifier(parts ...interface{}) string
Identifier works like SepIdentifier but the seperator is set to be a colon.
func KeyLessFunc ¶
KeyLessFunc compares the keys of two key/value pairs. It returns true if the key of a is less the key of b.
func LimitedSepIdentifier ¶
LimitedSepIdentifier builds an identifier out of multiple parts, all as lowercase strings and concatenated with the separator Non letters and digits are exchanged with dashes and reduced to a maximum of one each. If limit is true only 'a' to 'z' and '0' to '9' are allowed.
func MinuteInList ¶
Test if the minute of a time is in a given list.
func MinuteInRange ¶
Test if a minute of a time is in a given range.
func MonthInList ¶
Test if the month of a time is in a given list.
func MonthInRange ¶
Test if a month of a time is in a given range.
func SecondInList ¶
Test if the second of a time is in a given list.
func SecondInRange ¶
Test if a second of a time is in a given range.
func SepIdentifier ¶
SepIdentifier builds an identifier out of multiple parts, all as lowercase strings and concatenated with the separator Non letters and digits are exchanged with dashes and reduced to a maximum of one each.
func TypeAsIdentifierPart ¶
func TypeAsIdentifierPart(i interface{}) string
TypeAsIdentifierPart transforms the name of the arguments type into a part for identifiers. It's splitted at each uppercase char, concatenated with dashes and transferred to lowercase.
func WeekdayInList ¶
Test if the weekday of a time is in a given list.
func WeekdayInRange ¶
Test if a weekday of a time is in a given range.
func YearInList ¶
Test if the year of a time is in a given list.
Types ¶
type CachedValue ¶
type CachedValue struct {
// contains filtered or unexported fields
}
CachedValue retrieves and caches a value for a defined time. After that time the cache is cleared and set again automatically when accessed.
func NewCachedValue ¶
func NewCachedValue(r RetrievalFunc, ttl int64) *CachedValue
NewCachedValue creates a new cache.
func (*CachedValue) Stop ¶
func (cv *CachedValue) Stop()
Stop removes everything and sends a stop signal to the backend.
func (*CachedValue) Value ¶
func (cv *CachedValue) Value() (v interface{}, err os.Error)
Value returns the cached value. If an error occurred during retrieval that will be returned too.
type Crontab ¶
type Crontab struct {
// contains filtered or unexported fields
}
Crontab.
func (*Crontab) Recover ¶
func (ctb *Crontab) Recover(recoverable Recoverable, err interface{})
Recover after an error.
type DynamicStatusRetriever ¶
type DynamicStatusRetriever func() string
DynamicStatusRetriever is called by the server and returns a current status as string.
type FSM ¶
type FSM struct { Handler Handler // contains filtered or unexported fields }
State machine type.
func (*FSM) Recover ¶
func (fsm *FSM) Recover(recoverable Recoverable, err interface{})
Recover after an error.
func (*FSM) SendWithResult ¶
func (fsm *FSM) SendWithResult(payload interface{}) interface{}
Send a payload to handle and return the result.
type Hash ¶
type Hash map[string]interface{}
Hash is a map of string keys to any value.
type Heartbeat ¶
type Heartbeat struct { HeartbeatChan chan *Heartbeat ImAliveChan chan bool // contains filtered or unexported fields }
Heartbeat for one recoverable.
type Heartbeatable ¶
type Heartbeatable interface { Recoverable SetHearbeat(*Heartbeat) }
The interface for heartbeatable types.
type KeyValue ¶
type KeyValue struct { Key string Value interface{} }
KeyValue is a pair of a string key and any data as value.
type KeyValueChan ¶
type KeyValueChan chan *KeyValue
Channel for the transfer of key/value pairs.
func MapReduce ¶
func MapReduce(inChan KeyValueChan, mapFunc MapFunc, mapSize int, reduceFunc ReduceFunc, reduceSize int) KeyValueChan
MapReduce applies a map and a reduce function to keys and values in parallel.
func SortedMapReduce ¶
func SortedMapReduce(inChan KeyValueChan, mapFunc MapFunc, mapSize int, reduceFunc ReduceFunc, reduceSize int, lessFunc KeyValueLessFunc) KeyValueChan
SortedMapReduce performes a map/reduce and sorts the result.
type KeyValueLessFunc ¶
Less function for sorting.
type KeyValues ¶
type KeyValues struct { Data []*KeyValue LessFunc KeyValueLessFunc }
KeyValues is an ordered slice of keys and values, keys can occur multiple times.
func NewKeyValues ¶
func NewKeyValues(c int, kvlf KeyValueLessFunc) *KeyValues
NewKeyValues create a new empty key/value slice with size 0, capacity c and a less func for sorting.
func (*KeyValues) AppendChan ¶
func (kv *KeyValues) AppendChan(kvChan KeyValueChan)
AppendChan appends the key/values of a chan to this key/values.
func (*KeyValues) KeyValueChan ¶
func (kv *KeyValues) KeyValueChan() KeyValueChan
KeyValueChan returns a key/value channel and feeds it with the data.
func (*KeyValues) Less ¶
Less returns wether the key with index i should sort before the key with index j.
type MapFunc ¶
type MapFunc func(*KeyValue, KeyValueChan)
Map a key/value pair, emit to the channel.
type Measuring ¶
type Measuring struct {
// contains filtered or unexported fields
}
Measuring contains one measuring.
func (*Measuring) EndMeasuring ¶
EndMEasuring ends a measuring and passes it to the measuring server in the background.
type MeasuringPoint ¶
type MeasuringPoint struct { Id string Count int64 MinTime int64 MaxTime int64 TtlTime int64 AvgTime int64 }
MeasuringPoint contains the cumulated measuring data of one measuring point.
type Recoverable ¶
type Recoverable interface { Supervisor() *Supervisor Recover(Recoverable, interface{}) }
The interface for recoverable types.
type ReduceFunc ¶
type ReduceFunc func(KeyValueChan, KeyValueChan)
Reduce the key/values of the first channel, emit to the second channel.
type RetrievalFunc ¶
RetrievalFunc is the signature of a function responsible for the retrieval of the cached value from somewhere else in the system, e.g. a database.
type SmlReader ¶
type SmlReader struct {
// contains filtered or unexported fields
}
Reader for SML.
type SmlWriterProcessor ¶
type SmlWriterProcessor struct {
// contains filtered or unexported fields
}
Processor for writing SML.
func NewSmlWriterProcessor ¶
func NewSmlWriterProcessor(writer io.Writer, prettyPrint bool) *SmlWriterProcessor
Create a new SML writer processor.
func (*SmlWriterProcessor) CloseTag ¶
func (swp *SmlWriterProcessor) CloseTag(tag []string)
Close a tag.
func (*SmlWriterProcessor) OpenTag ¶
func (swp *SmlWriterProcessor) OpenTag(tag []string)
Open a tag.
type StaySetVariable ¶
type StaySetVariable struct { Id string Count int64 ActValue int64 MinValue int64 MaxValue int64 AvgValue int64 // contains filtered or unexported fields }
StaySetVariable contains the cumulated values for one stay-set variable.
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
The supervisor itself.
func (*Supervisor) AddRecoverable ¶
func (s *Supervisor) AddRecoverable(id string, r Recoverable)
Add a recoverable for joint restart in case of an error.
func (*Supervisor) Help ¶
func (s *Supervisor) Help(r Recoverable, err interface{})
Let a recoverable cry for help at its supervisor.
func (*Supervisor) Recover ¶
func (s *Supervisor) Recover(r Recoverable, err interface{})
Implement Recover() of the recoverable interface for the supervisor itself.
func (*Supervisor) Supervisor ¶
func (s *Supervisor) Supervisor() *Supervisor
Implement Supervisor() of the recoverable interface for the supervisor itself.
type SystemMonitor ¶
type SystemMonitor struct {
// contains filtered or unexported fields
}
The system monitor type.
func Monitor ¶
func Monitor() *SystemMonitor
Monitor returns the system monitor if it exists. Otherwise it creates it first.
func (*SystemMonitor) BeginMeasuring ¶
func (sm *SystemMonitor) BeginMeasuring(id string) *Measuring
BeginMeasuring starts a new measuring with a given id. All measurings with the same id will be aggregated.
func (*SystemMonitor) DynamicStatusValuesDo ¶
func (sm *SystemMonitor) DynamicStatusValuesDo(f func(string, string))
DynamicStatusValuesDo performs the function f for all status values.
func (*SystemMonitor) DynamicStatusValuesMap ¶
func (sm *SystemMonitor) DynamicStatusValuesMap(f func(string, string) interface{}) []interface{}
DynamicStatusValuesMap performs the function f for all status values and returns a slice with the return values of the function that are not nil.
func (*SystemMonitor) DynamicStatusValuesPrintAll ¶
func (sm *SystemMonitor) DynamicStatusValuesPrintAll()
DynamicStatusValuesPrintAll prints all status values to STDOUT.
func (*SystemMonitor) DynamicStatusValuesWrite ¶
DynamicStatusValuesWrite prints the status values for which the passed function returns true to the passed writer.
func (*SystemMonitor) Measure ¶
func (sm *SystemMonitor) Measure(id string, f func())
Measure the execution of a function.
func (*SystemMonitor) MeasuringPointsDo ¶
func (sm *SystemMonitor) MeasuringPointsDo(f func(*MeasuringPoint))
MeasuringPointsDo performs the function f for all measuring points.
func (*SystemMonitor) MeasuringPointsMap ¶
func (sm *SystemMonitor) MeasuringPointsMap(f func(*MeasuringPoint) interface{}) []interface{}
MeasuringPointsMap performs the function f for all measuring points and returns a slice with the return values of the function that are not nil.
func (*SystemMonitor) MeasuringPointsPrintAll ¶
func (sm *SystemMonitor) MeasuringPointsPrintAll()
MeasuringPointsPrintAll prints all measuring points to STDOUT.
func (*SystemMonitor) MeasuringPointsWrite ¶
func (sm *SystemMonitor) MeasuringPointsWrite(w io.Writer, ff func(*MeasuringPoint) bool)
MeasuringPointsWrite prints the measuring points for which the passed function returns true to the passed writer.
func (*SystemMonitor) Recover ¶
func (sm *SystemMonitor) Recover(recoverable Recoverable, err interface{})
Recover after an error.
func (*SystemMonitor) Register ¶
func (sm *SystemMonitor) Register(id string, rf DynamicStatusRetriever)
Register registers a new dynamic status retriever function.
func (*SystemMonitor) SetValue ¶
func (sm *SystemMonitor) SetValue(id string, v int64)
SetValue sets a value of a stay-set variable.
func (*SystemMonitor) StaySetVariablesDo ¶
func (sm *SystemMonitor) StaySetVariablesDo(f func(*StaySetVariable))
StaySetVariablesDo performs the function f for all variables.
func (*SystemMonitor) StaySetVariablesMap ¶
func (sm *SystemMonitor) StaySetVariablesMap(f func(*StaySetVariable) interface{}) []interface{}
StaySetVariablesMap performs the function f for all variables and returns a slice with the return values of the function that are not nil.
func (*SystemMonitor) StaySetVariablesPrintAll ¶
func (sm *SystemMonitor) StaySetVariablesPrintAll()
StaySetVariablesPrintAll prints all stay-set variables to STDOUT.
func (*SystemMonitor) StaySetVariablesWrite ¶
func (sm *SystemMonitor) StaySetVariablesWrite(w io.Writer, ff func(*StaySetVariable) bool)
StaySetVariablesWrite prints the stay-set variables for which the passed function returns true to the passed writer.
func (*SystemMonitor) Supervisor ¶
func (sm *SystemMonitor) Supervisor() *Supervisor
Return the supervisor.
func (*SystemMonitor) Unregister ¶
func (sm *SystemMonitor) Unregister(id string)
Unregister unregisters a dynamic status retriever function.
type TagNode ¶
type TagNode struct {
// contains filtered or unexported fields
}
The tag node.
func (*TagNode) AppendTagNode ¶
Append a tag node.
func (*TagNode) AppendTaggedText ¶
Append a tagged text node.
func (*TagNode) AppendText ¶
Append a text node.
func (*TagNode) AppendTextNode ¶
Append a text node.