shared

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package shared provides everything shared between entities.

Index

Constants

This section is empty.

Variables

View Source
var Paused int32 = 0

Paused is a flag that indicates if the pipeline is paused.

Functions

func Decode added in v0.1.2

func Decode(r io.Reader, v any) error

Decode process stream `r` into `v` and returns an error if any.

func Encode added in v0.1.2

func Encode(w io.Writer, v any) error

Encode process `v` into stream `w` and returns an error if any.

func ExtractID

func ExtractID[T any](t T, idFieldName string) string

ExtractID extracts `possibleIDFieldNames` from `v` - an arbitrary struct.

NOTE: Only exported fields are considered.

func Flatten2D

func Flatten2D[T any](data [][]T) []T

Flatten2D takes a 2D slice and returns a 1D slice containing all the elements.

func GenerateIDBasedOnContent

func GenerateIDBasedOnContent(ct string) string

GenerateIDBasedOnContent generates MD5 hash (content-based) for message ID. Good to be used to avoid duplicated messages.

func GenerateUUID

func GenerateUUID() string

GenerateUUID generates a RFC4122 UUID and DCE 1.1: Authentication and Security Services.

func GetPaused

func GetPaused() int32

GetPaused returns the `Paused` flag. It's concurrency-safe.

func Marshal added in v0.1.2

func Marshal(v any) ([]byte, error)

Marshal with custom error.

func ReadAll added in v0.1.2

func ReadAll(r io.Reader) ([]byte, error)

ReadAll reads all the data from `r` and returns an error if any.

func SetPaused

func SetPaused(val int32)

SetPaused sets the `Paused` flag. It's concurrency-safe.

func Unmarshal added in v0.1.2

func Unmarshal(data []byte, v any) error

Unmarshal with custom error.

Types

type IMeta

type IMeta interface {
	// GetName returns the `Name` of the entity.
	GetName() string

	// GetLogger returns the `Logger` of the entity.
	GetLogger() sypl.ISypl

	// GetDescription returns the `Description` of the processor.
	GetDescription() string

	// GetType returns the entity type.
	GetType() string
}

IMeta defines what an `Entity` must do.

type IMetrics

type IMetrics interface {
	// GetCounterCreated returns the `CounterCreated` metric.
	GetCounterCreated() *expvar.Int

	// GetCounterRunning returns the `CounterRunning` metric.
	GetCounterRunning() *expvar.Int

	// GetCounterFailed returns the `CounterFailed` metric.
	GetCounterFailed() *expvar.Int

	// GetCounterDone returns the `CounterDone` metric.
	GetCounterDone() *expvar.Int

	// GetStatus returns the `Status` metric.
	GetStatus() *expvar.String
}

IMetrics defines how to interact with the metrics.

type Run

type Run[In any] func(ctx context.Context, in []In) (out []In, err error)

Run is a function that transforms the data (`in`). It returns the transformed data and any errors that occurred during processing.

Jump to

Keyboard shortcuts

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