sugar

package
v0.0.0-...-973764b Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 13 Imported by: 0

README

语法糖

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed = errors.New("subscriber closed")
	ErrFull   = errors.New("message channel full")
)

Functions

func InArrayContain

func InArrayContain[T comparable](item T, items []T) bool

func LoadCertPool

func LoadCertPool(certPaths ...string) (*x509.CertPool, error)

LoadCertPool 从多个证书文件路径加载证书池

func PrintEsRequest

func PrintEsRequest(reqFun func(ctx context.Context) (*http.Request, error))

func RandInt

func RandInt(minV, maxV int) int

RandInt generate random int between [min, max).

func RandomWithProbability

func RandomWithProbability(probability float64) bool

RandomWithProbability 随机概率 0.01 -> 1.

func SliceLast

func SliceLast[T comparable](c []T) T

func SliceOf

func SliceOf[T any](val ...T) []T

Types

type Channel

type Channel[V any] struct {
	// contains filtered or unexported fields
}

func NewChannel

func NewChannel[V any](ctx context.Context, bufSize uint) *Channel[V]

func (*Channel[V]) Channel

func (s *Channel[V]) Channel() chan V

func (*Channel[V]) Close

func (s *Channel[V]) Close()

func (*Channel[V]) Push

func (s *Channel[V]) Push(v V) error

func (*Channel[V]) PushWithContext

func (s *Channel[V]) PushWithContext(ctx context.Context, v V) error

func (*Channel[V]) PushWithTimeout

func (s *Channel[V]) PushWithTimeout(msg V, timeout time.Duration) error

type Singleton

type Singleton[T any] interface {
	Load() T
	Inject(newFn func() T)
	Replace(newObj T)
}

func NewSingleton

func NewSingleton[T any](newFn func() T) Singleton[T]

type SingletonWithValue

type SingletonWithValue[T any, I any] interface {
	Singleton[T]

	Init(value I) T
	Reload(value I)
}

func NewSingletonWithValue

func NewSingletonWithValue[T any, I any](newFn func(I) T) SingletonWithValue[T, I]

Jump to

Keyboard shortcuts

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