eventbusx

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

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 15 Imported by: 0

README

readme

This code snippet is adapted from the watermill project "github.com/ThreeDotsLabs/watermill".

Original source: https://github.com/ThreeDotsLabs/watermill

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventArgsValueAs

func EventArgsValueAs[T any](e *EventArgs) *T

func NewShortUUID

func NewShortUUID() string

NewShortUUID returns a new short UUID.

func NewULID

func NewULID() string

NewULID returns a new ULID.

func NewUUID

func NewUUID() string

NewUUID returns a new UUID Version 4.

func Publish

func Publish[T any](v *T)

publish events, synchronized

func PublishAsync

func PublishAsync[T any](v *T)

publish events, asynchronized

func SetLogger

func SetLogger(loggerAdapter LoggerAdapter)

func Subscribe

func Subscribe[T any](observer IEventObserver)

func SubscribeWithAction

func SubscribeWithAction[T any](fn func(v *EventArgs))

Types

type CaptureLoggerAdapter

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

CaptureLoggerAdapter is a logger which captures all logs. This logger is mostly useful for testing logging.

func NewCaptureLogger

func NewCaptureLogger() *CaptureLoggerAdapter

func (*CaptureLoggerAdapter) Captured

func (c *CaptureLoggerAdapter) Captured() map[LogLevel][]CapturedMessage

func (*CaptureLoggerAdapter) Debug

func (c *CaptureLoggerAdapter) Debug(msg string, fields LogFields)

func (*CaptureLoggerAdapter) Error

func (c *CaptureLoggerAdapter) Error(msg string, err error, fields LogFields)

func (*CaptureLoggerAdapter) Has

func (*CaptureLoggerAdapter) HasError

func (c *CaptureLoggerAdapter) HasError(err error) bool

func (*CaptureLoggerAdapter) Info

func (c *CaptureLoggerAdapter) Info(msg string, fields LogFields)

func (*CaptureLoggerAdapter) Trace

func (c *CaptureLoggerAdapter) Trace(msg string, fields LogFields)

func (*CaptureLoggerAdapter) With

type CapturedMessage

type CapturedMessage struct {
	Level  LogLevel
	Fields LogFields
	Msg    string
	Err    error
}

type EventArgs

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

func NewEventArgs

func NewEventArgs(v *interface{}) *EventArgs

func (*EventArgs) Context

func (m *EventArgs) Context() context.Context

Context returns the message's context. To change the context, use SetContext.

The returned context is always non-nil; it defaults to the background context.

func (*EventArgs) SetContext

func (m *EventArgs) SetContext(ctx context.Context)

SetContext sets provided context to the message.

type IEventObserver

type IEventObserver interface {
	Notify(e *EventArgs)
}

func EventObserverFromAction

func EventObserverFromAction(action func(*EventArgs)) IEventObserver

type LogFields

type LogFields map[string]interface{}

LogFields is the logger's key-value list of fields.

func (LogFields) Add

func (l LogFields) Add(newFields LogFields) LogFields

Add adds new fields to the list of LogFields.

func (LogFields) Copy

func (l LogFields) Copy() LogFields

Copy copies the LogFields.

type LogLevel

type LogLevel uint
const (
	TraceLogLevel LogLevel = iota + 1
	DebugLogLevel
	InfoLogLevel
	ErrorLogLevel
)

type LoggerAdapter

type LoggerAdapter interface {
	Error(msg string, err error, fields LogFields)
	Info(msg string, fields LogFields)
	Debug(msg string, fields LogFields)
	Trace(msg string, fields LogFields)
	With(fields LogFields) LoggerAdapter
}

LoggerAdapter is an interface, that you need to implement to support Watermill logging. You can use StdLoggerAdapter as a reference implementation.

func NewStdLogger

func NewStdLogger(debug, trace bool) LoggerAdapter

NewStdLogger creates StdLoggerAdapter which sends all logs to stderr.

func NewStdLoggerWithOut

func NewStdLoggerWithOut(out io.Writer, debug bool, trace bool) LoggerAdapter

NewStdLoggerWithOut creates StdLoggerAdapter which sends all logs to provided io.Writer.

type NopLogger

type NopLogger struct{}

NopLogger is a logger which discards all logs.

func (NopLogger) Debug

func (NopLogger) Debug(msg string, fields LogFields)

func (NopLogger) Error

func (NopLogger) Error(msg string, err error, fields LogFields)

func (NopLogger) Info

func (NopLogger) Info(msg string, fields LogFields)

func (NopLogger) Trace

func (NopLogger) Trace(msg string, fields LogFields)

func (NopLogger) With

func (l NopLogger) With(fields LogFields) LoggerAdapter

type StdLoggerAdapter

type StdLoggerAdapter struct {
	ErrorLogger *log.Logger
	InfoLogger  *log.Logger
	DebugLogger *log.Logger
	TraceLogger *log.Logger
	// contains filtered or unexported fields
}

StdLoggerAdapter is a logger implementation, which sends all logs to provided standard output.

func (*StdLoggerAdapter) Debug

func (l *StdLoggerAdapter) Debug(msg string, fields LogFields)

func (*StdLoggerAdapter) Error

func (l *StdLoggerAdapter) Error(msg string, err error, fields LogFields)

func (*StdLoggerAdapter) Info

func (l *StdLoggerAdapter) Info(msg string, fields LogFields)

func (*StdLoggerAdapter) Trace

func (l *StdLoggerAdapter) Trace(msg string, fields LogFields)

func (*StdLoggerAdapter) With

func (l *StdLoggerAdapter) With(fields LogFields) LoggerAdapter

Directories

Path Synopsis
pubsub

Jump to

Keyboard shortcuts

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