beats: github.com/elastic/beats/libbeat/common/fmtstr Index | Files

package fmtstr

import "github.com/elastic/beats/libbeat/common/fmtstr"

Index

Package Files

formatevents.go formatstring.go

type EventFormatString Uses

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

EventFormatString implements format string support on events of type beat.Event.

The concrete event expansion requires the field name enclosed by brackets. For example: '%{[field.name]}'. Field names can be separated by points or multiple braces. This format `%{[field.name]}` is equivalent to `%{[field][name]}`.

Default values are given defined by the colon operator. For example: `%{[field.name]:default value}`.

func CompileEvent Uses

func CompileEvent(in string) (*EventFormatString, error)

CompileEvent compiles an event format string into an runnable EventFormatString. Returns error if parsing or compilation fails.

func MustCompileEvent Uses

func MustCompileEvent(in string) *EventFormatString

MustCompileEvent compiles an event format string into an runnable EventFormatString. Generates a panic if compilation fails.

func (*EventFormatString) Eval Uses

func (fs *EventFormatString) Eval(out *bytes.Buffer, event *beat.Event) error

Eval executes the format string, writing the resulting string into the provided output buffer. Returns error if execution or event field expansion fails.

func (*EventFormatString) Fields Uses

func (fs *EventFormatString) Fields() []string

Fields returns list of unique event fields required by the format string.

func (*EventFormatString) IsConst Uses

func (fs *EventFormatString) IsConst() bool

IsConst checks the format string always returning the same constant string

func (*EventFormatString) IsEmpty Uses

func (fs *EventFormatString) IsEmpty() bool

IsEmpty returns true if the format string expression is an empty string, can be used when validating to make defining a string mandatory.

func (*EventFormatString) NumFields Uses

func (fs *EventFormatString) NumFields() int

NumFields returns number of unique event fields used by the format string.

func (*EventFormatString) Run Uses

func (fs *EventFormatString) Run(event *beat.Event) (string, error)

Run executes the format string returning a new expanded string or an error if execution or event field expansion fails.

func (*EventFormatString) RunBytes Uses

func (fs *EventFormatString) RunBytes(event *beat.Event) ([]byte, error)

RunBytes executes the format string returning a new expanded string of type `[]byte` or an error if execution or event field expansion fails.

func (*EventFormatString) Unpack Uses

func (fs *EventFormatString) Unpack(v interface{}) error

Unpack tries to initialize the EventFormatString from provided value (which must be a string). Unpack method satisfies go-ucfg.Unpacker interface required by common.Config, in order to use EventFormatString with `common.(*Config).Unpack()`.

type FormatEvaler Uses

type FormatEvaler interface {
    // Eval will execute the format and writes the results into
    // the provided output buffer. Returns error on failure.
    Eval(ctx interface{}, out *bytes.Buffer) error
}

FormatEvaler evaluates some format.

type StringElement Uses

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

StringElement implements StringFormatter always returning a constant string.

func (StringElement) Eval Uses

func (e StringElement) Eval(_ interface{}, out *bytes.Buffer) error

Eval write the string elements constant string value into output buffer.

type StringFormatter Uses

type StringFormatter interface {
    FormatEvaler

    // Run execute the formatter returning the generated string.
    Run(ctx interface{}) (string, error)

    // IsConst returns true, if execution of formatter will always return the
    // same constant string.
    IsConst() bool
}

StringFormatter interface extends FormatEvaler adding support for querying formatter meta data.

func Compile Uses

func Compile(in string, vc VariableCompiler) (StringFormatter, error)

Compile compiles an input format string into a StringFormatter. The variable compiler `vc` is invoked for every variable expansion found in the input format string. Returns error on parse failure or if variable compiler fails.

Variable expansion are enclosed in expansion braces `%{<expansion>}`. The `<expansion>` can contain additional parameters separated by ops introduced by colons ':'. For example the format string `%{value:v1:?v2}` will be parsed into variable expansion on `value` with variable ops `[(":", "v1"), (":?", "v2")]`. It's up to the variable compiler to interpret content and variable ops.

The back-slash character `\` acts as escape character.

type VariableCompiler Uses

type VariableCompiler func(string, []VariableOp) (FormatEvaler, error)

VariableCompiler is used to compile a variable expansion into an FormatEvaler to be used with the format-string.

type VariableOp Uses

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

VariableOp defines one expansion variable, including operator and parameter. variable operations are always introduced by a colon ':'. For example the format string %{x:p1:?p2} has 2 variable operations (":", "p1") and (":?", "p2"). It's up to concrete format string implementation to compile and interpret variable ops.

Package fmtstr imports 12 packages (graph) and is imported by 107 packages. Updated 2019-08-15. Refresh now. Tools for package owners.