fmtstr

package
v6.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2018 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventFormatString

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

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

func MustCompileEvent(in string) *EventFormatString

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

func (*EventFormatString) Eval

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

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

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

func (*EventFormatString) IsConst

func (fs *EventFormatString) IsConst() bool

IsConst checks the format string always returning the same constant string

func (*EventFormatString) NumFields

func (fs *EventFormatString) NumFields() int

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

func (*EventFormatString) Run

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

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

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

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

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

StringElement implements StringFormatter always returning a constant string.

func (StringElement) Eval

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

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

type StringFormatter

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

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 collons ':'. 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

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

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

VariableOp defines one expansion variable, including operator and parameter. variable operations are always introduced by a collon ':'. 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.

Jump to

Keyboard shortcuts

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