ibento

package module
v0.0.0-...-0f56449 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: MIT Imports: 13 Imported by: 0

README

Embeddable, persistant event logging

Japanese for events

Documentation

Overview

Package ibento

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

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

Iterator

func (*Iterator) Consume

func (it *Iterator) Consume(f func(*event.Event) error) error

Consume

type Log

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

Log represents an readonly and append-only log of events

func Open

func Open(dir string, opts ...Option) (*Log, error)

Open opens a new event log.

Example
dir, err := ioutil.TempDir("", "*")
if err != nil {
	fmt.Println(err)
	return
}
defer os.RemoveAll(dir)

log, err := Open(dir)
if err != nil {
	fmt.Println(err)
	return
}
defer log.Close() // don't forget to close when done

fmt.Println("opened")
Output:

opened
Example (CustomOptions)
logger, err := zap.NewDevelopment()
if err != nil {
	fmt.Println(err)
	return
}

dir, err := ioutil.TempDir("", "*")
if err != nil {
	fmt.Println(err)
	return
}
defer os.RemoveAll(dir)

log, err := Open(dir, WithLogger(logger))
if err != nil {
	fmt.Println(err)
	return
}
defer log.Close() // don't forget to close when done

fmt.Println("opened")
Output:

opened

func (*Log) Append

func (l *Log) Append(ctx context.Context, ev event.Event) error

Append will add the given event to the end of a Log.

Example
dir, err := ioutil.TempDir("", "*")
if err != nil {
	fmt.Println(err)
	return
}
defer os.RemoveAll(dir)

log, err := Open(dir)
if err != nil {
	fmt.Println(err)
	return
}
defer log.Close() // don't forget to close when done

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

ev := event.New()
ev.SetSource("example")
ev.SetID("1")
ev.SetType("example")

err = log.Append(ctx, ev)
fmt.Println(err)
Output:

<nil>

func (*Log) Close

func (l *Log) Close() error

Close

func (*Log) Iterator

func (l *Log) Iterator() *Iterator

Iterator initializes a new iterator over the event log.

Example
dir, err := ioutil.TempDir("", "*")
if err != nil {
	fmt.Println(err)
	return
}
defer os.RemoveAll(dir)

eventlog, err := Open(dir)
if err != nil {
	fmt.Println(err)
	return
}
defer eventlog.Close() // don't forget to close when done

ev1 := event.New()
ev1.SetID("1234")
ev1.SetType("test")
ev1.SetSource("test")
err = eventlog.Append(context.Background(), ev1)
if err != nil {
	fmt.Println(err)
	return
}

ev2 := event.New()
ev2.SetID("4321")
ev2.SetType("test")
ev2.SetSource("test")
err = eventlog.Append(context.Background(), ev2)
if err != nil {
	fmt.Println(err)
	return
}

numOfEvents := 0
err = eventlog.
	Iterator().
	Consume(func(e *event.Event) error {
		numOfEvents += 1
		return nil
	})
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println(numOfEvents)
Output:

2

type Notification

type Notification struct {
	EventId     string
	EventSource string
	EventType   string
}

Notification represents that an event has been appended to the Log.

type Option

type Option func(*logOptions)

Option is a type which helps override the default Log configuration.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger

type ValidationError

type ValidationError struct {
	Cause error
}

ValidationError represents that an invalid parameter was provided to a method or function.

func (ValidationError) Error

func (e ValidationError) Error() string

Error implements the error interface.

func (ValidationError) Unwrap

func (e ValidationError) Unwrap() error

Unwrap

Jump to

Keyboard shortcuts

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