ena

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: MIT Imports: 6 Imported by: 1

README

ena

ena

Ena is An open-source golang library. And ena is Greek, which means ONE in english.

Documentation

Overview

Package ena provide the utility for golang.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnexpectPointer represent the obj is not an expected pointer type or value
	ErrUnexpectPointer = xerrors.Errorf("UnexpectPointer")
)

Functions

func ByteOrder

func ByteOrder() binary.ByteOrder

ByteOrder returns the byte order for the CPU's native endianness.

func EnforcePtr

func EnforcePtr(obj interface{}) (reflect.Value, error)

EnforcePtr ensures that obj is a pointer of some sort. Returns a reflect.Value of the dereferenced pointer, ensuring that it is settable/addressable. Returns an error if this is not possible.

func IndirectToSetableValue

func IndirectToSetableValue(i interface{}) (reflect.Value, error)

IndirectToSetableValue returns the setable reflect.Value of i

func IndirectToValue

func IndirectToValue(v interface{}) reflect.Value

IndirectToValue returns the reflect.Value of v If the interface is non reflect.Value, return the reflect.ValueOf(v)

func PointerTo

func PointerTo[T any](v T) *T

PointerTo returns a pointer to the passed value.

func ReceiveChannel

func ReceiveChannel[T any](ctx context.Context, ch <-chan interface{}) (v T, err error)

ReceiveChannel consume obj from channel, it will: 1. return err if ctx is Done 2. return err is obj is error 3. return err if obj is not error or type T

func ValueTo

func ValueTo[T any](p *T) (v T)

ValueTo returns a value for the passed pointer. If the pointer is nil, will return the empty value of T.

func ValueToOrDefault

func ValueToOrDefault[T any](p *T, d T) (v T)

ValueToOrDefault returns a value for the passed pointer. If the pointer is nil, will return the default value.

Types

type FnOption

type FnOption[T any] struct {
	Fn func(*T)
}

FnOption is an generic function helper for Option

func (*FnOption[T]) Apply

func (o *FnOption[T]) Apply(opt *T)

Apply will invoke fn on provide option

type NoCopy

type NoCopy struct{}

NoCopy may be embedded into structs which must not be copied after the first use.

See https://github.com/golang/go/issues/8005#issuecomment-190753527 for details.

func (*NoCopy) Lock

func (*NoCopy) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

type Option

type Option[T any] interface {
	// Apply applies this configuration to the given option
	Apply(*T)
}

Option is an generic configuration helper

func NewFnOption

func NewFnOption[T any](f func(*T)) Option[T]

NewFnOption will instant an Option with f

type WaitGroupWrapper

type WaitGroupWrapper struct {
	NoCopy
	// contains filtered or unexported fields
}

WaitGroupWrapper is a help struct for sync.WaitGroup

func (*WaitGroupWrapper) Wait

func (w *WaitGroupWrapper) Wait()

Wait will block until all cb finished

func (*WaitGroupWrapper) Wrap

func (w *WaitGroupWrapper) Wrap(cb func(), cbs ...func())

Wrap will handle sync.WaitGroup Add and Done

Directories

Path Synopsis
Package main is the entrance of project
Package main is the entrance of project
Package conma provide the machinism to load config from env、flag、file and configuration system.
Package conma provide the machinism to load config from env、flag、file and configuration system.
examples
Package main provide an example for use conma to retrieve configuration items
Package main provide an example for use conma to retrieve configuration items
Package conv provide the helper function to convert data types & string
Package conv provide the helper function to convert data types & string
Package delayqueue describe an delayqueue implemention.
Package delayqueue describe an delayqueue implemention.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
pkg
utils/version
Package version provide the information of current project module
Package version provide the information of current project module
Package priorityqueue describe an prioriry queue implement.
Package priorityqueue describe an prioriry queue implement.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package test contains some helper function for unittest and e2e-test
Package test contains some helper function for unittest and e2e-test
Package timingwheel implementation of Hierarchical Timing Wheels.
Package timingwheel implementation of Hierarchical Timing Wheels.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package wait provides utility functions for polling, listening using Go channel
Package wait provides utility functions for polling, listening using Go channel
Package xerrors contains the utility for errors.
Package xerrors contains the utility for errors.
Package xslog provide some helper for slog package.
Package xslog provide some helper for slog package.
Package xtime contains the utility for time.
Package xtime contains the utility for time.

Jump to

Keyboard shortcuts

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