engine

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2017 License: Apache-2.0 Imports: 12 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tail

func Tail(buffer *bytes.Buffer, n int) string

Tail returns the n last lines of a buffer stripped out of trailing white spaces, if any.

if n <= 0, returns an empty string

Types

type Decoder

type Decoder struct {
	*json.Decoder
}

func NewDecoder

func NewDecoder(src io.Reader) *Decoder

func (*Decoder) Decode

func (decoder *Decoder) Decode() (*Env, error)

type Env

type Env []string

func (*Env) Decode

func (env *Env) Decode(src io.Reader) error

DecodeEnv decodes `src` as a json dictionary, and adds each decoded key-value pair to the environment.

If `src` cannot be decoded as a json dictionary, an error is returned.

func (*Env) Encode

func (env *Env) Encode(dst io.Writer) error

func (*Env) Exists

func (env *Env) Exists(key string) bool

func (*Env) Get

func (env *Env) Get(key string) (value string)

Get returns the last value associated with the given key. If there are no values associated with the key, Get returns the empty string.

func (*Env) GetBool

func (env *Env) GetBool(key string) (value bool)

func (*Env) GetInt

func (env *Env) GetInt(key string) int

func (*Env) GetInt64

func (env *Env) GetInt64(key string) int64

func (*Env) GetJson

func (env *Env) GetJson(key string, iface interface{}) error

func (*Env) GetList

func (env *Env) GetList(key string) []string

Returns nil if key not found

func (*Env) GetSubEnv

func (env *Env) GetSubEnv(key string) *Env

func (*Env) GetTime

func (env *Env) GetTime(key string) (time.Time, error)

func (*Env) Import

func (env *Env) Import(src interface{}) (err error)

func (*Env) Init

func (env *Env) Init(src *Env)

func (*Env) InitMultiMap

func (env *Env) InitMultiMap(m map[string][]string)

InitMultiMap removes all values in env, then initializes new values from the contents of m.

func (*Env) Len

func (env *Env) Len() int

Len returns the number of keys in the environment. Note that len(env) might be different from env.Len(), because the same key might be set multiple times.

func (*Env) Map

func (env *Env) Map() map[string]string

func (*Env) MultiMap

func (env *Env) MultiMap() map[string][]string

MultiMap returns a representation of env as a map of string arrays, keyed by string. This is the same structure as http headers for example, which allow each key to have multiple values.

func (*Env) Set

func (env *Env) Set(key, value string)

func (*Env) SetAuto

func (env *Env) SetAuto(k string, v interface{})

func (*Env) SetBool

func (env *Env) SetBool(key string, value bool)

func (*Env) SetInt

func (env *Env) SetInt(key string, value int)

func (*Env) SetInt64

func (env *Env) SetInt64(key string, value int64)

func (*Env) SetJson

func (env *Env) SetJson(key string, value interface{}) error

func (*Env) SetList

func (env *Env) SetList(key string, value []string) error

func (*Env) SetSubEnv

func (env *Env) SetSubEnv(key string, sub *Env) error

func (*Env) SetTime

func (env *Env) SetTime(key string, t time.Time)

func (*Env) WriteJSON added in v0.6.0

func (env *Env) WriteJSON(w http.ResponseWriter, code int) error

func (*Env) WriteTo

func (env *Env) WriteTo(dst io.Writer) (int64, error)

type Input

type Input struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewInput

func NewInput() *Input

NewInput returns a new Input object with no source attached. Reading to an empty Input will return io.EOF.

func (*Input) Add

func (i *Input) Add(src io.Reader) error

Add attaches a new source to the input. Add can only be called once per input. Subsequent calls will return an error.

func (*Input) Close

func (i *Input) Close() error

Closes the src Not thread safe on purpose

func (*Input) Read

func (i *Input) Read(p []byte) (n int, err error)

Read reads from the input in a thread-safe way.

type Output

type Output struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewOutput

func NewOutput() *Output

NewOutput returns a new Output object with no destinations attached. Writing to an empty Output will cause the written data to be discarded.

func (*Output) Add

func (o *Output) Add(dst io.Writer)

Add attaches a new destination to the Output. Any data subsequently written to the output will be written to the new destination in addition to all the others. This method is thread-safe.

func (*Output) AddEnv

func (o *Output) AddEnv() (dst *Env, err error)

AddEnv starts a new goroutine which will decode all subsequent data as a stream of json-encoded objects, and point `dst` to the last decoded object. The result `env` can be queried using the type-neutral Env interface. It is not safe to query `env` until the Output is closed.

func (*Output) AddListTable

func (o *Output) AddListTable() (dst *Table, err error)

func (*Output) AddPipe

func (o *Output) AddPipe() (io.Reader, error)

AddPipe creates an in-memory pipe with io.Pipe(), adds its writing end as a destination, and returns its reading end for consumption by the caller. This is a rough equivalent similar to Cmd.StdoutPipe() in the standard os/exec package. This method is thread-safe.

func (*Output) AddTable

func (o *Output) AddTable() (dst *Table, err error)

func (*Output) Close

func (o *Output) Close() error

Close unregisters all destinations and waits for all background AddTail and AddString tasks to complete. The Close method of each destination is called if it exists.

func (*Output) Set

func (o *Output) Set(dst io.Writer)

Set closes and remove existing destination and then attaches a new destination to the Output. Any data subsequently written to the output will be written to the new destination in addition to all the others. This method is thread-safe.

func (*Output) Used

func (o *Output) Used() bool

Return true if something was written on this output

func (*Output) Write

func (o *Output) Write(p []byte) (n int, err error)

Write writes the same data to all registered destinations. This method is thread-safe.

type Table

type Table struct {
	Data []*Env

	Chan chan *Env
	// contains filtered or unexported fields
}

func NewTable

func NewTable(sortKey string, sizeHint int) *Table

func (*Table) Add

func (t *Table) Add(env *Env)

func (*Table) Len

func (t *Table) Len() int

func (*Table) Less

func (t *Table) Less(a, b int) bool

func (*Table) ReadFrom

func (t *Table) ReadFrom(src io.Reader) (n int64, err error)

func (*Table) ReadListFrom

func (t *Table) ReadListFrom(src []byte) (n int64, err error)

func (*Table) ReverseSort

func (t *Table) ReverseSort()

func (*Table) SetKey

func (t *Table) SetKey(sortKey string)

func (*Table) Sort

func (t *Table) Sort()

func (*Table) Swap

func (t *Table) Swap(a, b int)

func (*Table) ToListString

func (t *Table) ToListString() (string, error)

func (*Table) WriteListTo

func (t *Table) WriteListTo(dst io.Writer) (n int64, err error)

func (*Table) WriteTo

func (t *Table) WriteTo(dst io.Writer) (n int64, err error)

Jump to

Keyboard shortcuts

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