utils

package
v0.0.0-...-3cef9f2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrComparisonMismatch = errs.Class("reader comparer mismatch")
)

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, logger Logger) context.Context

func IdBytesGen

func IdBytesGen() []byte

func IdGen

func IdGen() string

func MarshalSized

func MarshalSized(pb proto.Message) ([]byte, error)

func Parallel

func Parallel(fn ...func() error) error

func PathSafeIdEncode

func PathSafeIdEncode(data []byte) string

func ReaderCompare

func ReaderCompare(readers ...io.ReadCloser) io.ReadCloser

ReaderCompare will return an io.ReadCloser that will error if any Reader returns data that doesn't match the others.

func ReaderTee

func ReaderTee(r io.Reader) (io.Reader, io.Reader)

ReaderTee turns a single Reader into two Readers that proceed in lockstep together with the same data.

func UnmarshalSized

func UnmarshalSized(source io.Reader, pb proto.Message) error

Types

type FramingReader

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

func NewFramingReader

func NewFramingReader(r io.Reader) *FramingReader

func (*FramingReader) Read

func (f *FramingReader) Read(p []byte) (n int, err error)

type LogLevel

type LogLevel int
var (
	Debug  LogLevel = 1
	Normal LogLevel = 2
	Urgent LogLevel = 3
	None   LogLevel = 4
)

func ParseLogLevel

func ParseLogLevel(val string) (LogLevel, error)

func (LogLevel) String

func (l LogLevel) String() string

type LogWrapper

type LogWrapper struct {
	Logger
}

func L

func L(ctx context.Context) LogWrapper

func (LogWrapper) Debugf

func (l LogWrapper) Debugf(format string, v ...interface{})

func (LogWrapper) Normalf

func (l LogWrapper) Normalf(format string, v ...interface{})

func (LogWrapper) Urgentf

func (l LogWrapper) Urgentf(format string, v ...interface{})

type Logger

type Logger interface {
	Printf(level LogLevel, format string, v ...interface{})
}

func StandardLogger

func StandardLogger(minLevel LogLevel) Logger

type LoggerFunc

type LoggerFunc func(level LogLevel, format string, v ...interface{})

func (LoggerFunc) Printf

func (f LoggerFunc) Printf(level LogLevel, format string, v ...interface{})

type ReaderBuf

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

ReaderBuf wraps a Reader with a goroutine that fills an internal buffer of the next read. Using ReaderBuf will keep the next read pipelined and ready. Calling a read (however small) will trigger the next pipelined read up to the internal buffer size. If you want many small reads, this should probably be wrapped in a bufio.Reader. ReaderBuf should be closed when done to make sure the goroutine gets shut down.

func NewReaderBuf

func NewReaderBuf(r io.ReadCloser) *ReaderBuf

func (*ReaderBuf) Close

func (rb *ReaderBuf) Close() error

Close shuts down any outstanding reads and the wrapped ReadCloser.

func (*ReaderBuf) Read

func (rb *ReaderBuf) Read(p []byte) (n int, err error)

Read will block until there is data in the internal buffer, but will otherwise read out of the internal buffer and signal that the next read can begin.

type ReaderFunc

type ReaderFunc func(p []byte) (n int, err error)

func (ReaderFunc) Read

func (f ReaderFunc) Read(p []byte) (n int, err error)

type UnframingReader

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

func NewUnframingReader

func NewUnframingReader(r io.Reader) *UnframingReader

func (*UnframingReader) Read

func (u *UnframingReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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