common

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EventTypeDataExtracted represents an event emitted when data is extracted from a source blockchain.
	EventTypeDataExtracted string = "data_extracted"

	// EventTypeDataTransformed represents an event emitted when data is transformed by a pipeline stage.
	EventTypeDataTransformed string = "data_transformed"

	// EventTypeDataLoaded represents an event emitted when data is loaded into a target blockchain.
	EventTypeDataLoaded string = "data_loaded"
)

Variables

This section is empty.

Functions

func HashSHA256

func HashSHA256(input string) string

hashSHA256 calculates the SHA-256 hash of the input string and returns the hexadecimal representation.

Types

type BusController

type BusController interface {
	// HasCallback checks if a handler is registered for the given topic.
	HasCallback(topic string) bool

	// WaitAsync blocks until all asynchronous operations are completed.
	WaitAsync()
}

BusController defines bus control behavior (checking handler's presence, synchronization).

type BusPublisher

type BusPublisher interface {
	// Publish publishes an event to the event bus.
	Publish(event Event)
}

BusPublisher defines publishing-related bus behavior.

type BusSubscriber

type BusSubscriber interface {
	// Subscribe subscribes to an event topic with the given parameters.
	Subscribe(params BusSubscriptionParams) error

	// SubscribeAsync subscribes to an event topic asynchronously with the given parameters.
	SubscribeAsync(params BusSubscriptionParams, transactional bool) error

	// SubscribeOnce subscribes to an event topic for a single event occurrence with the given parameters.
	SubscribeOnce(params BusSubscriptionParams) error

	// SubscribeOnceAsync subscribes to an event topic asynchronously for a single event occurrence with the given parameters.
	SubscribeOnceAsync(params BusSubscriptionParams) error

	// Unsubscribe unsubscribes from an event topic with the given parameters.
	Unsubscribe(params BusSubscriptionParams) error
}

BusSubscriber defines subscription-related bus behavior.

type BusSubscriptionParams

type BusSubscriptionParams struct {
	// Topic is the event topic to subscribe to.
	Topic string

	// EventHandler is the function that will handle the events for the subscribed topic.
	EventHandler EventHandler
}

BusSubscriptionParams represents the parameters for subscribing to an event topic.

type Context

type Context struct {
	// Embed the standard context.Context to inherit its methods and behavior.
	context.Context

	// PluginPaths is a slice of paths to search for plugins.
	PluginPaths []string

	// RemotePluginLocations is a slice of remote locations (e.g., GitHub repositories) to download plugins from.
	RemotePluginLocations []string
	// contains filtered or unexported fields
}

Context is a custom wrapper around the standard context.Context. It provides additional functionality such as logging, tracing, and custom cancelation logic.

func Background

func Background() *Context

Background returns a non-nil, empty Context. It is similar to the standard context.Background() function but returns a custom Context type.

func WithContext

func WithContext(ctx context.Context) *Context

Background returns a non-nil, empty Context. It is similar to the standard context.Background() function but returns a custom Context type.

func WithTimeout

func WithTimeout(parent *Context, timeout time.Duration) (*Context, context.CancelFunc)

WithTimeout returns a new Context with the given timeout duration. It is similar to the standard context.WithTimeout() function but returns a custom Context type and logs the timeout event.

func (*Context) Value

func (c *Context) Value(key interface{}) interface{}

Value returns the value associated with the given key in the context. It overrides the standard context.Value method to provide thread-safe access to the context values.

func (*Context) WithPluginPaths

func (c *Context) WithPluginPaths(paths ...string) *Context

WithPluginPaths returns a new Context with the given plugin paths.

func (*Context) WithRemotePluginLocations

func (c *Context) WithRemotePluginLocations(locations ...string) *Context

WithRemotePluginLocations returns a new Context with the given remote plugin locations.

func (*Context) WithTraceID

func (c *Context) WithTraceID(traceID string) *Context

WithTraceID returns a new Context with the given traceID associated with it.

func (*Context) WithValue

func (c *Context) WithValue(key, value interface{}) *Context

WithValue returns a new Context with the given key-value pair associated with it. It overrides the standard context.WithValue method to provide thread-safe access to the context values.

type Event

type Event struct {
	// Type is the type or identifier of the event.
	Type string

	// Data is the payload or data associated with the event.
	Data interface{}
}

Event represents an event within the system.

type EventBusInterface

type EventBusInterface interface {
	BusController
	BusSubscriber
	BusPublisher
}

EventBusInterface englobes global (subscribe, publish, control) bus behavior.

func NewSystemEventBus

func NewSystemEventBus() EventBusInterface

NewSystemEventBus creates a new instance of the SystemEventBus.

type EventHandler

type EventHandler func(event Event)

EventHandler defines the signature for an event handler function.

type IDGeneratorInterface

type IDGeneratorInterface interface {
	GenerateID() (string, error)
}

IDGeneratorInterface interface defines the behavior of a process ID generator.

type Level

type Level int

Level represents the severity level of a log message.

const (
	// LevelDebug represents the debug level log messages.
	LevelDebug Level = iota

	// LevelInfo represents the informational level log messages.
	LevelInfo

	// LevelWarn represents the warning level log messages.
	LevelWarn

	// LevelError represents the error level log messages.
	LevelError

	// LevelFatal represents the fatal level log messages.
	LevelFatal
)

func (Level) String

func (l Level) String() string

String returns the string representation of the log level.

type LoggerInterface

type LoggerInterface interface {
	// Print logs a message at the given level.
	Log(level Level, args ...interface{})

	// Printf logs a formatted message at the given level.
	Logf(level Level, format string, args ...interface{})
}

Logger is an interface for logging messages. It provides a standardized way to log messages, allowing different logging implementations to be used interchangeably.

type LogrusLogger

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

LogrusLogger is a concrete implementation of LoggerInterface using Logrus.

func NewLogrusLogger

func NewLogrusLogger(level Level) *LogrusLogger

NewLogrusLogger creates a new instance of LogrusLogger with the given log level.

func (*LogrusLogger) Log

func (l *LogrusLogger) Log(level Level, args ...interface{})

Log logs a message at the given level.

func (*LogrusLogger) Logf

func (l *LogrusLogger) Logf(level Level, format string, args ...interface{})

Logf logs a formatted message at the given level.

type ProcessIDGenerator

type ProcessIDGenerator struct {
	IDGeneratorInterface
	// contains filtered or unexported fields
}

RandomProcessIDGenerator provides functionality to generate unique process IDs.

func NewProcessIDGenerator

func NewProcessIDGenerator(prefix string) *ProcessIDGenerator

NewRandomProcessIDGenerator creates a new instance of RandomProcessIDGenerator with the given prefix.

func (*ProcessIDGenerator) GenerateID

func (gen *ProcessIDGenerator) GenerateID() (string, error)

GenerateID generates a unique process ID.

type SystemEventBus

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

SystemEventBus is a concrete implementation of the EventBusInterface.

func (*SystemEventBus) HasCallback

func (eb *SystemEventBus) HasCallback(topic string) bool

HasCallback checks if a handler is registered for the given topic.

func (*SystemEventBus) Publish

func (eb *SystemEventBus) Publish(event Event)

Publish publishes an event to the event bus.

func (*SystemEventBus) Subscribe

func (eb *SystemEventBus) Subscribe(params BusSubscriptionParams) error

Subscribe subscribes to an event topic with the given parameters.

func (*SystemEventBus) SubscribeAsync

func (eb *SystemEventBus) SubscribeAsync(params BusSubscriptionParams, transactional bool) error

SubscribeAsync subscribes to an event topic asynchronously with the given parameters.

func (*SystemEventBus) SubscribeOnce

func (eb *SystemEventBus) SubscribeOnce(params BusSubscriptionParams) error

SubscribeOnce subscribes to an event topic for a single event occurrence with the given parameters.

func (*SystemEventBus) SubscribeOnceAsync

func (eb *SystemEventBus) SubscribeOnceAsync(params BusSubscriptionParams) error

SubscribeOnceAsync subscribes to an event topic asynchronously for a single event occurrence with the given parameters.

func (*SystemEventBus) Unsubscribe

func (eb *SystemEventBus) Unsubscribe(params BusSubscriptionParams) error

Unsubscribe unsubscribes from an event topic with the given parameters.

func (*SystemEventBus) WaitAsync

func (eb *SystemEventBus) WaitAsync()

WaitAsync blocks until all asynchronous operations are completed.

Jump to

Keyboard shortcuts

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