Documentation ¶
Index ¶
- Constants
- Variables
- func Btoi(buffer []byte) (uint64, int)
- func DontPanic(callback func())
- func EscapeJSON(text string) string
- func GetMissingMethods(objType reflect.Type, ifaceType reflect.Type) (float32, []interface{})
- func IndexN(s, sep string, n int) int
- func IsDisconnectedError(err error) bool
- func IsJSON(data []byte) (bool, *json.RawMessage)
- func ItoLen(number uint64) int
- func Itob(number uint64, buffer []byte) error
- func Itobe(number uint64, buffer []byte) error
- func LastIndexN(s, sep string, n int) int
- func ListFilesByDateMatching(directory string, pattern string) ([]os.FileInfo, error)
- func Max3I(a, b, c int) int
- func MaxI(a, b int) int
- func Min3I(a, b, c int) int
- func MinI(a, b int) int
- func OpenNamedPipe(name string, perm uint32) (*os.File, error)
- func ParseAddress(addressString string) (address, protocol string)
- func RecoverShutdown()
- func SplitAddress(addressString string, defaultProtocol string) (protocol, host, port string, err error)
- func SplitPath(filePath string) (dir string, base string, ext string)
- func Unescape(text string) string
- type BufferReadCallback
- type BufferedReader
- type BufferedReaderFlags
- type ByteStream
- func (stream ByteStream) Bytes() []byte
- func (stream ByteStream) Cap() int
- func (stream ByteStream) Len() int
- func (stream *ByteStream) Read(target []byte) (int, error)
- func (stream *ByteStream) Reset()
- func (stream *ByteStream) ResetRead()
- func (stream *ByteStream) SetCapacity(capacity int)
- func (stream ByteStream) String() string
- func (stream *ByteStream) Write(source []byte) (int, error)
- func (stream *ByteStream) WriteByte(source byte) error
- func (stream *ByteStream) WriteString(source string) (int, error)
- type Expect
- func (e Expect) Equal(val1, val2 interface{}) bool
- func (e Expect) False(val bool) bool
- func (e Expect) Geq(val1, val2 interface{}) bool
- func (e Expect) Greater(val1, val2 interface{}) bool
- func (e Expect) Leq(val1, val2 interface{}) bool
- func (e Expect) Less(val1, val2 interface{}) bool
- func (e Expect) MapEqual(data interface{}, key interface{}, value interface{}) bool
- func (e Expect) MapGeq(data interface{}, key interface{}, value interface{}) bool
- func (e Expect) MapGreater(data interface{}, key interface{}, value interface{}) bool
- func (e Expect) MapLeq(data interface{}, key interface{}, value interface{}) bool
- func (e Expect) MapLess(data interface{}, key interface{}, value interface{}) bool
- func (e Expect) MapNeq(data interface{}, key interface{}, value interface{}) bool
- func (e Expect) MapNotSet(data interface{}, key interface{}) bool
- func (e Expect) MapSet(data interface{}, key interface{}) bool
- func (e Expect) Neq(val1, val2 interface{}) bool
- func (e Expect) Nil(val interface{}) bool
- func (e Expect) NoError(err error) bool
- func (e Expect) NonBlocking(t time.Duration, routine func()) bool
- func (e Expect) NotExecuted()
- func (e Expect) NotNil(val interface{}) bool
- func (e Expect) True(val bool) bool
- type FilesByDate
- type Fuse
- type MarshalMap
- func (mmap MarshalMap) Array(key string) ([]interface{}, error)
- func (mmap MarshalMap) Bool(key string) (bool, error)
- func (mmap MarshalMap) Float64(key string) (float64, error)
- func (mmap MarshalMap) Int(key string) (int, error)
- func (mmap MarshalMap) Int64(key string) (int64, error)
- func (mmap MarshalMap) Map(key string) (map[interface{}]interface{}, error)
- func (mmap MarshalMap) MarshalMap(key string) (MarshalMap, error)
- func (mmap MarshalMap) Path(key string) (interface{}, bool)
- func (mmap MarshalMap) String(key string) (string, error)
- func (mmap MarshalMap) StringArray(key string) ([]string, error)
- func (mmap MarshalMap) StringArrayMap(key string) (map[string][]string, error)
- func (mmap MarshalMap) StringMap(key string) (map[string]string, error)
- func (mmap MarshalMap) Uint64(key string) (uint64, error)
- type MetricServer
- type Mutex
- type ParsedFunc
- type ParserFlag
- type ParserStateID
- type SpinPriority
- type Spinner
- type StopListener
- type StopRequestError
- type Transition
- type TransitionDirective
- type TransitionParser
- func (parser *TransitionParser) Add(stateName string, token string, nextStateName string, flags ParserFlag, ...)
- func (parser *TransitionParser) AddDirectives(directives []TransitionDirective)
- func (parser *TransitionParser) AddTransition(stateName string, newTrans Transition, token string)
- func (parser *TransitionParser) GetStateID(stateName string) ParserStateID
- func (parser *TransitionParser) GetStateName(id ParserStateID) string
- func (parser *TransitionParser) Parse(data []byte, state string) ([]byte, ParserStateID)
- func (parser *TransitionParser) Stop(stateName string, token string, flags ParserFlag, callback ParsedFunc)
- type TrieNode
- type WaitGroup
Constants ¶
const ( // BufferedReaderFlagDelimiter enables reading for a delimiter. This flag is // ignored if an MLE flag is set. BufferedReaderFlagDelimiter = BufferedReaderFlags(0) // BufferedReaderFlagMLE enables reading if length encoded messages. // Runlength is read as ASCII (to uint64) until the first byte (ASCII char) // of the delimiter string. // Only one MLE flag is supported at a time. BufferedReaderFlagMLE = BufferedReaderFlags(1) // BufferedReaderFlagMLE8 enables reading if length encoded messages. // Runlength is read as binary (to uint8). // Only one MLE flag is supported at a time. BufferedReaderFlagMLE8 = BufferedReaderFlags(2) // BufferedReaderFlagMLE16 enables reading if length encoded messages. // Runlength is read as binary (to uint16). // Only one MLE flag is supported at a time. BufferedReaderFlagMLE16 = BufferedReaderFlags(3) // BufferedReaderFlagMLE32 enables reading if length encoded messages. // Runlength is read as binary (to uint32). // Only one MLE flag is supported at a time. BufferedReaderFlagMLE32 = BufferedReaderFlags(4) // BufferedReaderFlagMLE64 enables reading if length encoded messages. // Runlength is read as binary (to uint64). // Only one MLE flag is supported at a time. BufferedReaderFlagMLE64 = BufferedReaderFlags(5) // BufferedReaderFlagMLEFixed enables reading messages with a fixed length. // Only one MLE flag is supported at a time. BufferedReaderFlagMLEFixed = BufferedReaderFlags(6) // BufferedReaderFlagMaskMLE is a bitmask to mask out everything but MLE flags BufferedReaderFlagMaskMLE = BufferedReaderFlags(7) // BufferedReaderFlagBigEndian sets binary reading to big endian encoding. BufferedReaderFlagBigEndian = BufferedReaderFlags(8) // BufferedReaderFlagEverything will keep MLE and/or delimiters when // building a message. BufferedReaderFlagEverything = BufferedReaderFlags(16) )
const ( // MetricProcessStart is the metric name storing the time when this process // has been started. MetricProcessStart = "ProcessStart" // MetricGoRoutines is the metric name storing the number of active go // routines. MetricGoRoutines = "GoRoutines" // MetricGoVersion holds the go version as Major*10000+Minor*100+Patch MetricGoVersion = "GoVersion" // MetricMemoryAllocated holds the currently active memory in bytes MetricMemoryAllocated = "GoMemoryAllocated" // MetricMemoryNumObjects holds the total number of allocated heap objects MetricMemoryNumObjects = "GoMemoryNumObjects" // MetricMemoryGCEnabled holds 1 or 0 depending on the state of garbage collection MetricMemoryGCEnabled = "GoMemoryGCEnabled" )
const ( // ParserFlagContinue continues parsing at the position of the match. // By default the matched token will be skipped. This flag prevents the // default behavior. In addition to that the parser will add the parsed // token to the value of the next match. ParserFlagContinue = ParserFlag(1 << iota) // ParserFlagAppend causes the parser to keep the current value for the next // match. By default a value will be restarted after each match. This flag // prevents the default behavior. ParserFlagAppend = ParserFlag(1 << iota) // ParserFlagInclude includes the matched token in the read value. // By default the value does not contain the matched token. ParserFlagInclude = ParserFlag(1 << iota) // ParserFlagPush pushes the current state on the stack before making the // transition. ParserFlagPush = ParserFlag(1 << iota) // ParserFlagPop pops the stack and uses the returned state as the next // state. If no state is on the stack the regular next state is used. ParserFlagPop = ParserFlag(1 << iota) // ParserStateStop defines a state that causes the parsing to stop when // transitioned into. ParserStateStop = ParserStateID(0xFFFFFFFF) )
const ( // SpinPrioritySuspend should be used for spinning loops that are expected // to wait for very long periods of time. The loop will sleep for 1 second // after each iteration. SpinPrioritySuspend = SpinPriority(1) // SpinPriorityLow should be used for spinning loops that are expected to // spin for a rather long time before being able to exit. // After 100 loops the caller waits for 200 milliseconds. SpinPriorityLow = SpinPriority(100) // SpinPriorityMedium should be used for spinning loops that are expected to // spin for a short amount of time before being able to exit. // After 500 loops the caller waits for 100 milliseconds. SpinPriorityMedium = SpinPriority(500) // SpinPriorityHigh should be used for spinning loops that are expected to // almost never spin. // After 1000 loops the caller waits for 10 milliseconds. SpinPriorityHigh = SpinPriority(1000) // SpinPriorityRealtime should be used for loops that should never wait and // always spin. This priority will increase CPU load SpinPriorityRealtime = SpinPriority(0xFFFFFFFF) // SpinTimeSuspend holds the sleep time for SpinPrioritySuspend SpinTimeSuspend = time.Second // SpinTimeLow holds the sleep time for SpinPriorityLow SpinTimeLow = 200 * time.Millisecond // SpinTimeMedium holds the sleep time for SpinPriorityMedium SpinTimeMedium = 100 * time.Millisecond // SpinTimeHigh holds the sleep time for SpinPriorityHigh SpinTimeHigh = 10 * time.Millisecond )
Variables ¶
var BufferDataInvalid = bufferError("Invalid data")
BufferDataInvalid is returned when a parsing encounters an error
Metric allows any part of gollum to store and/or modify metric values by name.
var ProcessStartTime time.Time
ProcessStartTime stores the time this process has started. This value is also stored in the metric MetricProcessStart
var TypeRegistry = typeRegistry{ // contains filtered or unexported fields }
TypeRegistry is the global typeRegistry instance. Use this instance to register plugins.
Functions ¶
func Btoi ¶
Btoi is a fast byte buffer to unsigned int parser that reads until the first non-number character is found. It returns the number value as well as the length of the number string encountered. If a number could not be parsed the returned length will be 0
func DontPanic ¶ added in v0.4.0
func DontPanic(callback func())
DontPanic can be used instead of RecoverShutdown when using a function without any parameters. E.g. go DontPanic(myFunction)
func EscapeJSON ¶ added in v0.4.2
EscapeJSON replaces occurrences of \ and " with escaped versions.
func GetMissingMethods ¶
GetMissingMethods checks if a given object implements all methods of a given interface. It returns the interface coverage [0..1] as well as an array of error messages. If the interface is correctly implemented the coverage is 1 and the error message array is empty.
func IndexN ¶ added in v0.4.0
IndexN returns the nth occurrence of sep in s or -1 if there is no nth occurrence of sep.
func IsDisconnectedError ¶ added in v0.4.0
IsDisconnectedError returns true if the given error is related to a disconnected socket.
func IsJSON ¶ added in v0.4.5
func IsJSON(data []byte) (bool, *json.RawMessage)
IsJSON tries to marshal a byte stream as JSON. Returns true if successful and also provides a result handle.
func LastIndexN ¶ added in v0.4.0
LastIndexN returns the nth occurrence of sep in s or -1 if there is no nth occurrence of sep. Searching is going from the end of the string to the start.
func ListFilesByDateMatching ¶ added in v0.4.0
ListFilesByDateMatching gets all files from a directory that match a given regular expression pattern and orders them by modification date (ascending). Directories and symlinks are excluded from the returned list.
func OpenNamedPipe ¶ added in v0.4.5
OpenNamedPipe opens or attaches to a named pipe given by name. If the pipe is created, perm will be used as file permissions. This function is not available on windows.
func ParseAddress ¶
ParseAddress takes an address and tries to extract the protocol from it. Protocols may be prepended by the "protocol://" notation. If no protocol is given, "tcp" is assumed. The first parameter returned is the address, the second denotes the protocol. The protocol is allways returned as lowercase string.
func RecoverShutdown ¶
func RecoverShutdown()
RecoverShutdown will trigger a shutdown via interrupt if a panic was issued. Typically used as "defer RecoverShutdown()".
func SplitAddress ¶ added in v0.4.1
func SplitAddress(addressString string, defaultProtocol string) (protocol, host, port string, err error)
SplitAddress splits an address of the form "protocol://host:port" into its components. If no protocol is given, the default protocol is used. This function uses net.SplitHostPort.
Types ¶
type BufferReadCallback ¶
BufferReadCallback defines the function signature for callbacks passed to ReadAll.
type BufferedReader ¶
type BufferedReader struct {
// contains filtered or unexported fields
}
BufferedReader is a helper struct to read from any io.Reader into a byte slice. The data can arrive "in pieces" and will be assembled. A data "piece" is considered complete if a delimiter or a certain runlength has been reached. The latter has to be enabled by flag and will disable the default behavior, which is looking for a delimiter string. In addition to that every data "piece" will receive an incrementing sequence number.
func NewBufferedReader ¶
func NewBufferedReader(bufferSize int, flags BufferedReaderFlags, offsetOrLength int, delimiter string) *BufferedReader
NewBufferedReader creates a new buffered reader that reads messages from a continuous stream of bytes. Messages can be separated from the stream by using common methods such as fixed size, encoded message length or delimiter string. The internal buffer is grown statically (by its original size) if necessary. bufferSize defines the initial size / grow size of the buffer flags configures the parsing method offsetOrLength sets either the runlength offset or fixed message size delimiter defines the delimiter used for textual message parsing
func (*BufferedReader) ReadAll ¶
func (buffer *BufferedReader) ReadAll(reader io.Reader, callback BufferReadCallback) error
ReadAll calls ReadOne as long as there are messages in the stream. Messages will be send to the given write callback. If callback is nil, data will be read and discarded.
func (*BufferedReader) ReadOne ¶
func (buffer *BufferedReader) ReadOne(reader io.Reader) (data []byte, seq uint64, more bool, err error)
ReadOne reads the next message from the given stream (if possible) and generates a sequence number for this message. The more return parameter is set to true if there are still messages or parts of messages in the stream. Data and seq is only set if a complete message could be parsed. Errors are returned if reading from the stream failed or the parser encountered an error.
func (*BufferedReader) Reset ¶
func (buffer *BufferedReader) Reset(sequence uint64)
Reset clears the buffer by resetting its internal state
type BufferedReaderFlags ¶
type BufferedReaderFlags byte
BufferedReaderFlags is an enum to configure a buffered reader
type ByteStream ¶
type ByteStream struct {
// contains filtered or unexported fields
}
ByteStream is a more lightweight variant of bytes.Buffer. The managed byte array is increased to the exact required size and never shrinks. Writing moves an internal offset (for appends) but reading always starts at offset 0.
func NewByteStream ¶
func NewByteStream(capacity int) ByteStream
NewByteStream creates a new byte stream of the desired capacity
func NewByteStreamFrom ¶
func NewByteStreamFrom(data []byte) ByteStream
NewByteStreamFrom creates a new byte stream that starts with the given byte array.
func (ByteStream) Bytes ¶
func (stream ByteStream) Bytes() []byte
Bytes returns a slice of the underlying byte array containing all written data up to this point.
func (ByteStream) Cap ¶
func (stream ByteStream) Cap() int
Cap returns the capacity of the underlying array. This is equal to cap(stream.Bytes()).
func (ByteStream) Len ¶
func (stream ByteStream) Len() int
Len returns the length of the underlying array. This is equal to len(stream.Bytes()).
func (*ByteStream) Read ¶
func (stream *ByteStream) Read(target []byte) (int, error)
Read implements the io.Reader interface. The underlying array is copied to target and io.EOF is returned once no data is left to be read. Please note that ResetRead can rewind the internal read index for this operation.
func (*ByteStream) Reset ¶
func (stream *ByteStream) Reset()
Reset sets the internal write offset to 0 and calls ResetRead
func (*ByteStream) ResetRead ¶ added in v0.4.1
func (stream *ByteStream) ResetRead()
ResetRead sets the internal read offset to 0. The read offset is only used within the Read function to assure io.Reader compatibility
func (*ByteStream) SetCapacity ¶
func (stream *ByteStream) SetCapacity(capacity int)
SetCapacity assures that capacity bytes are available in the buffer, growing the managed byte array if needed. The buffer will grow by at least 64 bytes if growing is required.
func (ByteStream) String ¶
func (stream ByteStream) String() string
String returns a string of the underlying byte array containing all written data up to this point.
func (*ByteStream) Write ¶
func (stream *ByteStream) Write(source []byte) (int, error)
Write implements the io.Writer interface. This function assures that the capacity of the underlying byte array is enough to store the incoming amount of data. Subsequent writes will allways append to the end of the stream until Reset() is called.
func (*ByteStream) WriteByte ¶
func (stream *ByteStream) WriteByte(source byte) error
WriteByte writes a single byte to the stream. Capacity will be ensured.
func (*ByteStream) WriteString ¶
func (stream *ByteStream) WriteString(source string) (int, error)
WriteString is a convenience wrapper for Write([]byte(source))
type Expect ¶
type Expect struct {
// contains filtered or unexported fields
}
Expect is a helper construct for unittesting
func NewExpect ¶
NewExpect creates an Expect helper struct with scope set to the name of the calling function.
func (Expect) Equal ¶
Equal does a deep equality check on both values and returns true if that test yielded true (val1 == val2)
func (Expect) Geq ¶
Geq does a numeric greater or equal check on both values and returns true if that test yielded true (val1 >= val2)
func (Expect) Greater ¶
Greater does a numeric greater than check on both values and returns true if that test yielded true (val1 > val2)
func (Expect) Leq ¶
Leq does a numeric less or euqal check on both values and returns true if that test yielded true (val1 <= val2)
func (Expect) Less ¶
Less does a numeric less than check on both values and returns true if that test yielded true (val1 < val2)
func (Expect) MapEqual ¶
MapEqual returns true if MapSet equals true for the given key and Equal returns true for the returned and given value.
func (Expect) MapGeq ¶
MapGeq returns true if MapSet equals true for the given key and Geq returns true for the returned and given value.
func (Expect) MapGreater ¶
MapGreater returns true if MapSet equals true for the given key and Greater returns true for the returned and given value.
func (Expect) MapLeq ¶
MapLeq returns true if MapSet equals true for the given key and Leq returns true for the returned and given value.
func (Expect) MapLess ¶
MapLess returns true if MapSet equals true for the given key and Less returns true for the returned and given value.
func (Expect) MapNeq ¶
MapNeq returns true if MapSet equals true for the given key and Neq returns true for the returned and given value.
func (Expect) Neq ¶
Neq does a deep equality check on both values and returns true if that test yielded false (val1 != val2)
func (Expect) NoError ¶
NoError tests if the given error is nil. If it is not the error will be logged.
func (Expect) NonBlocking ¶ added in v0.4.1
NonBlocking waits for the given timeout for the routine to return. If timed out it is an error.
func (Expect) NotExecuted ¶ added in v0.4.0
func (e Expect) NotExecuted()
NotExecuted always reports an error when called
type FilesByDate ¶ added in v0.4.0
FilesByDate implements the Sort interface by Date for os.FileInfo arrays
func (FilesByDate) Len ¶ added in v0.4.0
func (files FilesByDate) Len() int
Len returns the number of files in the array
func (FilesByDate) Less ¶ added in v0.4.0
func (files FilesByDate) Less(a, b int) bool
Less compares the date of the files stored at a and b as in "[a] modified < [b] modified". If both files were created in the same second the file names are compared by using a lexicographic string compare.
func (FilesByDate) Swap ¶ added in v0.4.0
func (files FilesByDate) Swap(a, b int)
Swap exchanges the values stored at indexes a and b
type Fuse ¶ added in v0.4.1
type Fuse struct {
// contains filtered or unexported fields
}
Fuse is a local circuit breaker implementation that is ment to be used to manage the state of a given resource between different threads of execution (consumer/producer). If the resource is not available the fuse is "burned". Components may now wait on that fuse and are woken as soon as the resource becomes available again (the fuse is "activated" again).
func NewFuse ¶ added in v0.4.1
func NewFuse() *Fuse
NewFuse creates a new Fuse and returns it. A new fuse is always active.
func (*Fuse) Activate ¶ added in v0.4.1
func (fuse *Fuse) Activate()
Activate sets the fuse back to the "running" state. An already active fuse cannot be activated again (call is ignored).
func (*Fuse) Burn ¶ added in v0.4.1
func (fuse *Fuse) Burn()
Burn sets the fuse back to the "inactive" state. An already burned fuse cannot be burned again (call is ignored).
type MarshalMap ¶
type MarshalMap map[string]interface{}
MarshalMap is a wrapper type to attach converter methods to maps normally returned by marshalling methods, i.e. key/value parsers. All methods that do a conversion will return an error if the value stored behind key is not of the expected type or if the key is not existing in the map.
func NewMarshalMap ¶
func NewMarshalMap() MarshalMap
NewMarshalMap creates a new marshal map (string -> interface{})
func (MarshalMap) Array ¶
func (mmap MarshalMap) Array(key string) ([]interface{}, error)
Array returns a value at key that is expected to be a []interface{}
func (MarshalMap) Bool ¶
func (mmap MarshalMap) Bool(key string) (bool, error)
Bool returns a value at key that is expected to be a boolean
func (MarshalMap) Float64 ¶
func (mmap MarshalMap) Float64(key string) (float64, error)
Float64 returns a value at key that is expected to be a float64
func (MarshalMap) Int ¶
func (mmap MarshalMap) Int(key string) (int, error)
Int returns a value at key that is expected to be an int
func (MarshalMap) Int64 ¶
func (mmap MarshalMap) Int64(key string) (int64, error)
Int64 returns a value at key that is expected to be an int64
func (MarshalMap) Map ¶
func (mmap MarshalMap) Map(key string) (map[interface{}]interface{}, error)
Map returns a value at key that is expected to be a map[interface{}]interface{}.
func (MarshalMap) MarshalMap ¶
func (mmap MarshalMap) MarshalMap(key string) (MarshalMap, error)
MarshalMap returns a value at key that is expected to be another MarshalMap This function supports conversion (by copy) from
- map[interface{}]interface{}
func (MarshalMap) Path ¶
func (mmap MarshalMap) Path(key string) (interface{}, bool)
Path returns a value from a given value path. Fields can be accessed by their name. Nested fields can be accessed by using "/" as a separator. Arrays can be addressed using the standard array notation "[<index>]". Examples: "key" -> mmap["key"] single value "key1/key2" -> mmap["key1"]["key2"] nested map "key1[0]" -> mmap["key1"][0] nested array "key1[0]key2" -> mmap["key1"][0]["key2"] nested array, nested map
func (MarshalMap) String ¶
func (mmap MarshalMap) String(key string) (string, error)
Array returns a value at key that is expected to be a string
func (MarshalMap) StringArray ¶
func (mmap MarshalMap) StringArray(key string) ([]string, error)
StringArray returns a value at key that is expected to be a []string This function supports conversion (by copy) from
- []interface{}
func (MarshalMap) StringArrayMap ¶
func (mmap MarshalMap) StringArrayMap(key string) (map[string][]string, error)
StringArrayMap returns a value at key that is expected to be a map[string][]string. This function supports conversion (by copy) from
- map[interface{}][]interface{}
- map[interface{}]interface{}
- map[string]interface{}
type MetricServer ¶
type MetricServer struct {
// contains filtered or unexported fields
}
MetricServer contains state information about the metric server process
func NewMetricServer ¶
func NewMetricServer() *MetricServer
NewMetricServer creates a new server state for a metric server
func (*MetricServer) Start ¶
func (server *MetricServer) Start(port int)
Start causes a metric server to listen for a specific port. If this port is accessed a JSON containing all metrics will be returned and the connection is closed.
func (*MetricServer) Stop ¶
func (server *MetricServer) Stop()
Stop notifies the metric server to halt.
type Mutex ¶ added in v0.4.1
type Mutex struct {
// contains filtered or unexported fields
}
Mutex is a lightweight, spinner based mutex implementation, extending the standard go mutex by the possibility to query the mutexe's state. This state is very volatile but can come in handy sometimes.
func NewMutex ¶ added in v0.4.1
func NewMutex(priority SpinPriority) *Mutex
NewMutex creates a new mutex with the given spin priority used during Lock.
func (*Mutex) IsLocked ¶ added in v0.4.1
IsLocked returns the state of this mutex. The result of this function might change directly after call so it should only be used in situations where this fact is not considered problematic.
type ParsedFunc ¶
type ParsedFunc func([]byte, ParserStateID)
ParsedFunc defines a function that a token has been matched
type ParserFlag ¶
type ParserFlag int
ParserFlag is an enum type for flags used in parser transitions.
type ParserStateID ¶
type ParserStateID uint32
ParserStateID is used as an integer-based reference to a specific parser state. You can use any number (e.g. a hash) as a parser state representative.
type SpinPriority ¶ added in v0.4.0
type SpinPriority uint32
SpinPriority is used for Spinner priority enum values
type Spinner ¶ added in v0.4.0
type Spinner struct {
// contains filtered or unexported fields
}
Spinner is a helper struct for spinning loops.
func NewSpinner ¶ added in v0.4.0
func NewSpinner(priority SpinPriority) Spinner
NewSpinner creates a new helper for spinning loops
type StopListener ¶
type StopListener struct { *net.TCPListener // contains filtered or unexported fields }
StopListener is a wrapper around net.TCPListener that allows to gracefully shut down a connection loop.
func NewStopListener ¶
func NewStopListener(address string) (*StopListener, error)
NewStopListener creates a new, stoppable TCP server connection. Address needs to be cmpliant to net.Listen.
func (*StopListener) Accept ¶
func (listen *StopListener) Accept() (net.Conn, error)
Accept is analogous to net.TCPListener.Accept but may return a connection closed error if the connection was requested to shut down.
func (*StopListener) Close ¶
func (listen *StopListener) Close() error
Close requests a connection close on this listener
type StopRequestError ¶
type StopRequestError struct{}
StopRequestError is not an error but a note that the connection was requested to be closed.
func (StopRequestError) Error ¶
func (err StopRequestError) Error() string
Error implements the standard error interface
type Transition ¶
type Transition struct {
// contains filtered or unexported fields
}
Transition defines a token based state change
func NewTransition ¶
func NewTransition(nextState ParserStateID, flags ParserFlag, callback ParsedFunc) Transition
NewTransition creates a new transition to a given state.
type TransitionDirective ¶
type TransitionDirective struct { State string Token string NextState string Flags ParserFlag Callback ParsedFunc }
TransitionDirective contains a transition description that can be passed to the AddDirectives functions.
func ParseTransitionDirective ¶
func ParseTransitionDirective(config string, callbacks map[string]ParsedFunc) (TransitionDirective, error)
ParseTransitionDirective creates a transition directive from a string. This string must be of the following format:
State:Token:NextState:Flag,Flag,...:Function
Spaces will be stripped from all fields but Token. If a fields requires a colon it has to be escaped with a backslash. Other escape characters supported are \n, \r and \t. Flag can be a set of the following flags (input will be converted to lowercase):
- continue -> ParserFlagContinue
- append -> ParserFlagAppend
- include -> ParserFlagInclude
- push -> ParserFlagPush
- pop -> ParserFlagPop
The name passed to the function token must be in the callbacks map. If it is not the data of the token will not be written. I.e. in empty string equals "do not write" here. An empty NextState will be translated to the "Stop" state as ususal.
type TransitionParser ¶
type TransitionParser struct {
// contains filtered or unexported fields
}
TransitionParser defines the behavior of a parser by storing transitions from one state to another.
func NewTransitionParser ¶
func NewTransitionParser() TransitionParser
NewTransitionParser creates a new transition based parser
func (*TransitionParser) Add ¶
func (parser *TransitionParser) Add(stateName string, token string, nextStateName string, flags ParserFlag, callback ParsedFunc)
Add adds a new transition to a given parser state.
func (*TransitionParser) AddDirectives ¶
func (parser *TransitionParser) AddDirectives(directives []TransitionDirective)
AddDirectives is a convenience function to add multiple transitions in as a batch.
func (*TransitionParser) AddTransition ¶
func (parser *TransitionParser) AddTransition(stateName string, newTrans Transition, token string)
AddTransition adds a transition from a given state to the map
func (*TransitionParser) GetStateID ¶
func (parser *TransitionParser) GetStateID(stateName string) ParserStateID
GetStateID creates a hash from the given state name. Empty state names will be translated to ParserStateStop.
func (*TransitionParser) GetStateName ¶
func (parser *TransitionParser) GetStateName(id ParserStateID) string
GetStateName returns the name for the given state id or an empty string if the id could not be found.
func (*TransitionParser) Parse ¶
func (parser *TransitionParser) Parse(data []byte, state string) ([]byte, ParserStateID)
Parse starts parsing at a given stateID. This function returns the remaining parts of data that did not match a transition as well as the last state the parser has been set to.
func (*TransitionParser) Stop ¶
func (parser *TransitionParser) Stop(stateName string, token string, flags ParserFlag, callback ParsedFunc)
Stop adds a stop transition to a given parser state.
type TrieNode ¶
type TrieNode struct { PathLen int Payload interface{} // contains filtered or unexported fields }
TrieNode represents a single node inside a trie. Each node can contain a payload which can be retrieved after a successful match. In addition to that PathLen will contain the length of the match.
func (*TrieNode) Add ¶
Add adds a new data path to the trie. The TrieNode returned is the (new) root node so you should always reassign the root with the return value of Add.
func (*TrieNode) ForEach ¶
ForEach applies a function to each node in the tree including and below the passed node.
func (*TrieNode) Match ¶
Match compares the trie to the given data stream. Match returns true if data can be completely matched to the trie.
func (*TrieNode) MatchStart ¶
MatchStart compares the trie to the beginning of the given data stream. MatchStart returns true if the beginning of data can be matched to the trie.
type WaitGroup ¶ added in v0.4.0
type WaitGroup struct {
// contains filtered or unexported fields
}
WaitGroup is a replacement for sync/waitgroup that allows the internal counter to go negative. This version allows a missed Done to be recovered but will make it a lot harder to detect missing Done or Add calls. Use only where needed.
func (*WaitGroup) Add ¶ added in v0.4.0
Add increments the waitgroup counter by the given value. Delta may be negative.
func (*WaitGroup) Done ¶ added in v0.4.0
func (wg *WaitGroup) Done()
Done is the shorthand version for Add(-1)
func (*WaitGroup) Inc ¶ added in v0.4.0
func (wg *WaitGroup) Inc()
Inc is the shorthand version for Add(1)
func (*WaitGroup) IncWhenDone ¶ added in v0.4.0
func (wg *WaitGroup) IncWhenDone()
IncWhenDone wait until the counter is exactly 0 and triggeres an increment if this is found to be true