common

package
v0.0.0-...-f5bbbf4 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(a, b []string) []string

Diff returns the elements in `a` that aren't in `b` Good algorithm as it's O(n) instead of a naive O(n2)

func InterfaceToObject

func InterfaceToObject(data, result interface{}) error

func RandHexString

func RandHexString(n int) string

func RandInt

func RandInt(n int) int

func RandIntRange

func RandIntRange(min, max int) int

func RandString

func RandString(n int) string

func ToMap

func ToMap(a []string) map[string]struct{}

func ToPtr

func ToPtr(v interface{}) interface{}

func Tomapstr

func Tomapstr(m map[string]*string) map[string]string

func Tomapstrptr

func Tomapstrptr(m map[string]string) map[string]*string

Types

type Checkable

type Checkable interface {
	ID() string

	// CheckLiveness MUST return an error if the long living task is not running otherwise nil
	CheckLiveness(context.Context) error

	// CheckReadiness MUST return an error if the long living task is not running otherwise nil
	CheckReadiness(context.Context) error
}

Checkable allows to

type Runnable

type Runnable interface {
	// Start long living task in a parallel goroutine
	//
	// It MUST return an error if and only if it failed at starting the long living task
	Start(context.Context) error

	// Stop gracefully interrupts long living task
	//
	// Stop SHOULD make sure underlying long living task has gracefully interrupted execution before returning
	//
	// In case context timeouts or is canceled Stop MUST
	// 1. [optional] Try to kill long living task (MUST not block on doing this)
	// 2. Return immediately with an error
	//
	// In any other case Stop MUST not return before the long live task
	// has gracefully interrupted execution
	Stop(context.Context) error

	// Close clean the runnable
	//
	// Init, Start, Stop, MUST NOT be called after Close
	Close() error

	// Error returns any possible error met by the runnable
	//
	// It MAY be
	// - an error that raised Init, Start, Stop or Close
	// - an error that raised on the long living task which force prematured Stop
	Error() error
}

Runnable manages running long living task

type SignalListener

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

SignalListener listen to signals and trigger callbacks

func NewSignalListener

func NewSignalListener(cb func(os.Signal)) *SignalListener

NewSignalListener creates a new SignalListener

func (*SignalListener) Close

func (l *SignalListener) Close()

Close signal listener

type WriterWrapper

type WriterWrapper interface {
	Writer() io.Writer
}

Jump to

Keyboard shortcuts

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