util

package
v0.0.0-...-4d179a5 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultChannelSize = 10
)

Variables

View Source
var (
	ErrNegativeRead   = errors.New("util.StaticBuffer: reader returned negative count from Read")
	ErrInvalidWrite   = errors.New("util.StaticBuffer: writer returned invalid count from Write")
	ErrNotEnoughSpace = errors.New("util.StaticBuffer: not enough space left for writting")
)
View Source
var (
	ErrInvalidUUIDString = errors.New("invalid uuid string format")
	InvalidUUID          = UUID{0}
)
View Source
var (
	ErrIteratorEOF = errors.New("Iterator reaches EOF")
)

Functions

func UUIDStringGen

func UUIDStringGen() (string, error)

Types

type AsyncExecutor

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

AsyncExecutor deal with a bunch of input data Buf make sure that those input data belongs to the same Request Because only one context associated with the Executor And there's supposed to be only one context bound to one Request

func NewAsyncExecutor

func NewAsyncExecutor(h Handler) *AsyncExecutor

func (*AsyncExecutor) Run

func (e *AsyncExecutor) Run(ctx context.Context, in <-chan interface{}) (<-chan interface{}, <-chan error, error)

type Closer

type Closer interface {
	Close() error
}

type Executor

type Executor interface {
	Run(ctx context.Context, in <-chan interface{}) (<-chan interface{}, <-chan error, error)
}

type FanInAsyncExecutor

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

FanInExecutor is a converge executor , In charge of merging multiple channels' output into one single channel

func NewFanInAsyncExecutor

func NewFanInAsyncExecutor(h Handler) *FanInAsyncExecutor

func (*FanInAsyncExecutor) Run

func (f *FanInAsyncExecutor) Run(ctx context.Context,
	in []<-chan interface{}, errs []<-chan error) (<-chan interface{}, <-chan error, error)

type FanInExecutor

type FanInExecutor interface {
	Run(ctx context.Context, in []<-chan interface{}, errs []<-chan error) (<-chan interface{}, <-chan error, error)
}

type FanOutAsyncExecutor

type FanOutAsyncExecutor struct {
}

FanOutExecutor expand the data processing of one intput channel to multiple executor Notice that the caller should handle the output channel slice

func NewFanOutAsyncExecutor

func NewFanOutAsyncExecutor() *FanOutAsyncExecutor

func (*FanOutAsyncExecutor) Run

func (f *FanOutAsyncExecutor) Run(ctx context.Context,
	in <-chan interface{},
	executors []Executor) ([]<-chan interface{}, []<-chan error, error)

type FanOutExecutor

type FanOutExecutor interface {
	Run(ctx context.Context, in <-chan interface{}, executors []Executor) ([]<-chan interface{}, []<-chan error, error)
}

type Handler

type Handler interface {
	Init() error

	Handle(ctx context.Context, d interface{}) (interface{}, error)

	Finish() error
}

The interface for handling request

type IterateCloser

type IterateCloser interface {
	Iterator
	Closer
}

If the iterator needs some cleanning work when done this could be the choice

type Iterator

type Iterator interface {
	Next(ctx context.Context) (interface{}, error)
}

This could be the result of a handler if th handler intends to generate a collection of data. When the iteration done, return EOF error

type OffsetWriter

type OffsetWriter struct {
	W      io.WriterAt //WriterAt interface
	Offset int64       //Write offset
}

func NewOffsetWriter

func NewOffsetWriter(wa io.WriterAt, offset int64) *OffsetWriter

func (*OffsetWriter) Write

func (ow *OffsetWriter) Write(p []byte) (int, error)

type StaticBuffer

type StaticBuffer struct {
	Buf []byte // buffer
	W   int64  // start point of writting
	R   int64  // start point of reading
}

func NewStaticBuffer

func NewStaticBuffer(cap int64) *StaticBuffer

func (*StaticBuffer) Cap

func (sb *StaticBuffer) Cap() int64

func (*StaticBuffer) Close

func (sb *StaticBuffer) Close() error

func (*StaticBuffer) Read

func (sb *StaticBuffer) Read(p []byte) (int, error)

func (*StaticBuffer) ReadFrom

func (sb *StaticBuffer) ReadFrom(r io.Reader) (int64, error)

func (*StaticBuffer) Reset

func (sb *StaticBuffer) Reset()

func (*StaticBuffer) Size

func (sb *StaticBuffer) Size() int64

func (*StaticBuffer) Write

func (sb *StaticBuffer) Write(p []byte) (int, error)

func (*StaticBuffer) WriteTo

func (sb *StaticBuffer) WriteTo(w io.Writer) (int64, error)

type UUID

type UUID uuid.UUID

func UUIDFromString

func UUIDFromString(s string) (UUID, error)

func UUIDGen

func UUIDGen() (UUID, error)

func (UUID) String

func (id UUID) String() string

Jump to

Keyboard shortcuts

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