Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyTranslation(element interface{}, key, formatString string) (string, error)
- func AsString(value interface{}) (string, bool)
- func ExitOnError(err error, msg string)
- func FailOnError(err error, msg string)
- func FindStringSubmatchMap(re *regexp.Regexp, s string) map[string]string
- func FindStringSubmatchMapWithRegexExpression(re RegexExpression, s string) map[string]string
- func GetField(object interface{}, fieldPath string) (interface{}, error)
- func GetStringField(a interface{}, field string) string
- func NewID() string
- func RandString(n int) string
- func ReadFile(path string) ([]byte, error)
- func StringInSlice(a string, list []string) bool
- func TimeTrack(start time.Time, name string)
- func ToSnakeCase(str string) string
- func TruncateString(s string, chars int) string
- type OptionalBool
- type OptionalInt64
- type OptionalInterface
- type OptionalRegexp
- type OptionalString
- type OptionalStringArray
- type OptionalTemplate
- type RegexExpression
- type WrapperBuiltInRegex
- type WrapperRegex2
Constants ¶
const ( Regexp2MatchTimeout = "REGEXP2_MATCH_TIMEOUT" DefaultRegex2MatchTimeout = time.Second )
const NamingCharacterSet = "abcdefghijklmnopqrstuvwxyz1234567890"
Variables ¶
var NumberOfCharacter = int64(len(NamingCharacterSet))
Functions ¶
func ApplyTranslation ¶
ApplyTranslation translate a templated string using informations in an Event
func AsString ¶
AsString tries to convert an interface{} into a string, and returns its value and an integer indicating whether it succeeded or not.
func ExitOnError ¶
ExitOnError calls log.Fatalf if err != nil
func FailOnError ¶
FailOnError calls log.Panicf if err != nil
func FindStringSubmatchMap ¶
FindStringSubmatchMap returns a map containing the values of the named subexpressions of the lefmost match of the regular expression re in s. A return value of nil indicates no match.
func FindStringSubmatchMapWithRegexExpression ¶
func FindStringSubmatchMapWithRegexExpression(re RegexExpression, s string) map[string]string
FindStringSubmatchMap returns a map containing the values of the named subexpressions of the lefmost match of the regular expression re in s. A return value of nil indicates no match.
func GetField ¶
GetField returns the value of a field of an object or a map, given the field's name as a string. Multiple field names may be chained, separated by dots:
GetField(alarm_value, "State.Value")
An error is returned if the field does not exist. If the field is a pointer, it will be dereferenced before being returned. Note that GetField cannot return map keys that contain a dot.
func GetStringField ¶
GetStringField read a string field in a struct, with introspection
func StringInSlice ¶
StringInSlice checks if a string is present in a list of strings
func ToSnakeCase ¶
ToSnakeCase changes case of string to snake case.
func TruncateString ¶
Types ¶
type OptionalBool ¶
type OptionalBool struct { // Set is a boolean indicating whether the value was set or not. Set bool // Value contains the value of the bool. It should only be taken into // account if Set is true. Value bool }
OptionalBool is a wrapper around bool that implements the bson.Setter interface.
Using this type instead of bool in a struct allows to :
- check whether the value was set or not in the bson document.
- raise an error when trying to unmarshal a value that is not an integer.
Note that when trying to unmarshal a value that is not a bool, UnmarshalBSONValue will raise an error that will not be handled by bson.Unmarshal. If this error is not handled in the UnmarshalBSONValue method of an ancestor, calls to MongoDB queries may fail.
func (OptionalBool) MarshalBSONValue ¶
func (s OptionalBool) MarshalBSONValue() (bsontype.Type, []byte, error)
func (*OptionalBool) UnmarshalBSONValue ¶
func (s *OptionalBool) UnmarshalBSONValue(valueType bsontype.Type, b []byte) error
type OptionalInt64 ¶
type OptionalInt64 struct { // Set is a boolean indicating whether the value was set or not. Set bool // Value contains the value of the int64. It should only be taken into // account if Set is true. Value int64 }
OptionalInt64 is a wrapper around int64 that implements the bson.Setter interface.
Using this type instead of int64 in a struct allows to :
- check whether the value was set or not in the bson document.
- raise an error when trying to unmarshal a value that is not an integer.
Note that when trying to unmarshal a value that is not an integer, UnmarshalBSONValue will raise an error that will not be handled by bson.Unmarshal. If this error is not handled in the UnmarshalBSONValue method of an ancestor, calls to MongoDB queries may fail.
func (OptionalInt64) MarshalBSONValue ¶
func (i OptionalInt64) MarshalBSONValue() (bsontype.Type, []byte, error)
func (*OptionalInt64) UnmarshalBSONValue ¶
func (i *OptionalInt64) UnmarshalBSONValue(valueType bsontype.Type, b []byte) error
type OptionalInterface ¶
type OptionalInterface struct { // Set is a boolean indicating whether the value was set or not. Set bool // Value contains the value of the interface{}. It should only be taken // into account if Set is true. Value interface{} }
OptionalInterface is a wrapper around interface{} that implements the bson.Setter interface.
Using this type instead of interface{} in a struct allows to check whether the value was set or not in the bson document.
func (OptionalInterface) MarshalBSONValue ¶
func (i OptionalInterface) MarshalBSONValue() (bsontype.Type, []byte, error)
func (*OptionalInterface) UnmarshalBSONValue ¶
func (i *OptionalInterface) UnmarshalBSONValue(valueType bsontype.Type, b []byte) error
type OptionalRegexp ¶
type OptionalRegexp struct { // Set is a boolean indicating whether the value was set or not. Set bool // Value contains the value of the regular expression. It should only be // taken into account if Set is true. Value RegexExpression }
OptionalRegexp is a wrapper around regexp.Regexp that implements the bson.Setter interface.
Using this type in a struct allows to :
- check whether the value was set or not in the bson document.
- automatically compile a regular expression.
- raise an error when trying to unmarshal a value that is not a valid regular expression.
Note that when trying to unmarshal a value that is not a valid regular expression, UnmarshalBSONValue will raise an error that will not be handled by bson.Unmarshal. If this error is not handled in the UnmarshalBSONValue method of an ancestor, calls to MongoDB queries may fail.
func (OptionalRegexp) MarshalBSONValue ¶
func (r OptionalRegexp) MarshalBSONValue() (bsontype.Type, []byte, error)
func (*OptionalRegexp) UnmarshalBSONValue ¶
func (r *OptionalRegexp) UnmarshalBSONValue(valueType bsontype.Type, b []byte) error
type OptionalString ¶
type OptionalString struct { // Set is a boolean indicating whether the value was set or not. Set bool // Value contains the value of the string. It should only be taken into // account if Set is true. Value string }
OptionalString is a wrapper around string that implements the bson.Setter interface.
Using this type instead of string in a struct allows to :
- check whether the value was set or not in the bson document.
- raise an error when trying to unmarshal a value that is not an integer.
Note that when trying to unmarshal a value that is not a string, UnmarshalBSONValue will raise an error that will not be handled by bson.Unmarshal. If this error is not handled in the UnmarshalBSONValue method of an ancestor, calls to MongoDB queries may fail.
func (OptionalString) MarshalBSONValue ¶
func (s OptionalString) MarshalBSONValue() (bsontype.Type, []byte, error)
func (*OptionalString) UnmarshalBSONValue ¶
func (s *OptionalString) UnmarshalBSONValue(valueType bsontype.Type, b []byte) error
type OptionalStringArray ¶
func (OptionalStringArray) MarshalBSONValue ¶
func (a OptionalStringArray) MarshalBSONValue() (bsontype.Type, []byte, error)
func (*OptionalStringArray) UnmarshalBSONValue ¶
func (a *OptionalStringArray) UnmarshalBSONValue(valueType bsontype.Type, b []byte) error
type OptionalTemplate ¶
type OptionalTemplate struct { // Set is a boolean indicating whether the value was set or not. Set bool // Value contains the value of the regular expression. It should only be // taken into account if Set is true. Value *template.Template }
OptionalTemplate is a wrapper around template.Template that implements the bson.Setter interface.
Using this type in a struct allows to :
- check whether the value was set or not in the bson document.
- automatically compile a template.
- raise an error when trying to unmarshal a value that is not a valid template.
Note that when trying to unmarshal a value that is not a valid template, UnmarshalBSONValue will raise an error that will not be handled by bson.Unmarshal. If this error is not handled in the UnmarshalBSONValue method of an ancestor, calls to MongoDB queries may fail.
func (OptionalTemplate) MarshalBSONValue ¶
func (t OptionalTemplate) MarshalBSONValue() (bsontype.Type, []byte, error)
func (*OptionalTemplate) UnmarshalBSONValue ¶
func (t *OptionalTemplate) UnmarshalBSONValue(valueType bsontype.Type, b []byte) error
type RegexExpression ¶
func NewRegexExpression ¶
func NewRegexExpression(expr string) (RegexExpression, error)
type WrapperBuiltInRegex ¶
type WrapperRegex2 ¶
func (WrapperRegex2) Match ¶
func (r WrapperRegex2) Match(content []byte) bool