events

package module
v0.0.0-...-ed1a75c Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

go-events

See examples under events-example

Documentation

Overview

Copyright 2017 Jeff Nickoloff "jeff@allingeek.com"

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2017 Jeff Nickoloff "jeff@allingeek.com"

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, config EventsConfig) context.Context

func PublishInflux

func PublishInflux(url, db string, maxIdle time.Duration) chan EventBlock

PublishInflux returns a channel of EventBlocks and starts a goroutine that reads from that channel and writes retireved EventBlocks using the InfluxDB client library. Closing the returned channel will stop the associated goroutine.

func PublishLog

func PublishLog() chan EventBlock

PublishLog returns a channel of EventBlocks after it starts a goroutine that reads from that channel writing the EventBlocks to STDOUT via the log package. Closing the channel will stop the goroutine.

func Write

func Write(ctx context.Context, es ...Event) error

Types

type Counter

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

func NewCounter

func NewCounter(name string) *Counter

func (*Counter) Add

func (c *Counter) Add(d float64)

func (*Counter) Name

func (c *Counter) Name() string

func (*Counter) Pair

func (c *Counter) Pair() Pair

func (*Counter) Value

func (c *Counter) Value() float64

type Event

type Event interface {
	Name() string
	Value() float64
	Pair() Pair
}

type EventBlock

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

type EventsConfig

type EventsConfig struct {
	Tags     map[string]string
	Registry *Registry
}

func FromContext

func FromContext(ctx context.Context) (EventsConfig, bool)

type Pair

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

func (*Pair) Name

func (p *Pair) Name() string

func (*Pair) Pair

func (p *Pair) Pair() Pair

func (*Pair) Value

func (p *Pair) Value() float64

type Registry

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

func NewRegistry

func NewRegistry(timeout time.Duration, log *log.Logger) *Registry

func (*Registry) Publish

func (r *Registry) Publish(eb EventBlock)

Publish is called by the goroutine that has gathered events - typically via the Write function. Publish is synchronous on a per-Registry basis however, the actual publication operation for each subscriber happens asynchronously in separate goroutines.

In the event that a subscriber's channel is closed it will be automatically unsubscribed from the Registry.

Publication to each subscriber will timeout after the duration specified during Registry configuration. In such an event the EventBlock will not be written to the subscriber and an error message will be written to the log. Automatically unsubscribing the subscriber in this case would cause more significant data loss in the event of a transient backpressure issue.

func (*Registry) Subscribe

func (r *Registry) Subscribe(name string, c chan EventBlock)

Subscribe is idempotent for a given subscription name

func (*Registry) Unsubscribe

func (r *Registry) Unsubscribe(name string)

type Timer

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

func NewStartedTimer

func NewStartedTimer(name string) *Timer

func NewTimer

func NewTimer(name string) *Timer

func (*Timer) Name

func (t *Timer) Name() string

func (*Timer) Pair

func (t *Timer) Pair() Pair

func (*Timer) Start

func (t *Timer) Start() *Timer

func (*Timer) Stop

func (t *Timer) Stop() *Timer

func (*Timer) Value

func (t *Timer) Value() float64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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