orange

package module
v0.0.0-...-ab8cfff Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2020 License: Apache-2.0 Imports: 28 Imported by: 0

README

orange

orange is a network framework written in Go (Golang).orange makes development as simple as possible。

The vast majority of the code for this project is a copy of the kubernetes project, the author only made a combination, if there is infringement also please email to inform。

Documentation

Index

Constants

View Source
const (
	HTTP proto = iota
	TCP
	UDP
	HTTP2
)

Variables

View Source
var ErrPreconditionViolated = errors.New("precondition is violated")

ErrPreconditionViolated is returned when the precondition is violated

View Source
var ErrWaitTimeout = errors.New("timed out waiting for the condition")

ErrWaitTimeout is returned when the condition exited without success.

View Source
var ErrorHandlers = []func(error){
	logError,
	(&rudimentaryErrorBackoff{
		lastErrorTime: time.Now(),

		minPeriod: time.Millisecond,
	}).OnError,
}

ErrorHandlers is a list of functions which will be invoked when an unreturnable error occurs. TODO(lavalamp): for testability, this and the below HandleError function should be packaged up into a testable and reusable object.

View Source
var ForeverTestTimeout = time.Second * 30

For any test of the style:

...
<- time.After(timeout):
   t.Errorf("Timed out")

The value for timeout should effectively be "forever." Obviously we don't want our tests to truly lock up forever, but 30s is long enough that it is effectively forever for the things that can slow down a run on a heavily contended machine (GC, seeks, etc), but not so long as to make a developer ctrl-c a test run if they do happen to break that test.

View Source
var NeverStop <-chan struct{} = make(chan struct{})

NeverStop may be passed to Until to make it never stop.

View Source
var PanicHandlers = []func(interface{}){logPanic}

PanicHandlers is a list of functions which will be invoked when a panic happens.

View Source
var (
	// ReallyCrash controls the behavior of HandleCrash and now defaults
	// true. It's still exposed so components can optionally set to false
	// to restore prior behavior.
	ReallyCrash = true
)

Functions

func BackoffUntil

func BackoffUntil(f func(), backoff BackoffManager, sliding bool, stopCh <-chan struct{})

BackoffUntil loops until stop channel is closed, run f every duration given by BackoffManager.

If sliding is true, the period is computed after f runs. If it is false then period includes the runtime for f.

func ExponentialBackoff

func ExponentialBackoff(backoff Backoff, condition ConditionFunc) error

ExponentialBackoff repeats a condition check with exponential backoff.

It checks the condition up to Steps times, increasing the wait by multiplying the previous duration by Factor.

If Jitter is greater than zero, a random amount of each duration is added (between duration and duration*(1+jitter)).

If the condition never returns true, ErrWaitTimeout is returned. All other errors terminate immediately.

func FilterOut

func FilterOut(err error, fns ...Matcher) error

FilterOut removes all errors that match any of the matchers from the input error. If the input is a singular error, only that error is tested. If the input implements the Aggregate interface, the list of errors will be processed recursively.

This can be used, for example, to remove known-OK errors (such as io.EOF or os.PathNotFound) from a list of errors.

func FinishRequest

func FinishRequest(timeout time.Duration, fn resultFunc) (result interface{}, err error)

finishRequest makes a given resultFunc asynchronous and handles errors returned by the response. An api.Status object with status != success is considered an "error", which interrupts the normal response flow.

func Forever

func Forever(f func(), period time.Duration)

Forever calls f every period for ever.

Forever is syntactic sugar on top of Until.

func GetCaller

func GetCaller() string

GetCaller returns the caller of the function that calls it.

func HandleCrash

func HandleCrash(additionalHandlers ...func(interface{}))

HandleCrash simply catches a crash and logs an error. Meant to be called via defer. Additional context-specific handlers can be provided, and will be called in case of panic. HandleCrash actually crashes, after calling the handlers and logging the panic message.

E.g., you can provide one or more additional handlers for something like shutting down go routines gracefully.

func HandleError

func HandleError(err error)

HandlerError is a method to invoke when a non-user facing piece of code cannot return an error and needs to indicate it has been ignored. Invoking this method is preferable to logging the error - the default behavior is to log but the errors may be sent to a remote server for analysis.

func Jitter

func Jitter(duration time.Duration, maxFactor float64) time.Duration

Jitter returns a time.Duration between duration and duration + maxFactor * duration.

This allows clients to avoid converging on periodic behavior. If maxFactor is 0.0, a suggested default value will be chosen.

func JitterUntil

func JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, stopCh <-chan struct{})

JitterUntil loops until stop channel is closed, running f every period.

If jitterFactor is positive, the period is jittered before every run of f. If jitterFactor is not positive, the period is unchanged and not jittered.

If sliding is true, the period is computed after f runs. If it is false then period includes the runtime for f.

Close stopCh to stop. f may not be invoked if stop channel is already closed. Pass NeverStop to if you don't want it stop.

func JitterUntilWithContext

func JitterUntilWithContext(ctx context.Context, f func(context.Context), period time.Duration, jitterFactor float64, sliding bool)

JitterUntilWithContext loops until context is done, running f every period.

func Must

func Must(err error)

Must panics on non-nil errors. Useful to handling programmer level errors.

func NonSlidingUntil

func NonSlidingUntil(f func(), period time.Duration, stopCh <-chan struct{})

NonSlidingUntil loops until stop channel is closed, running f every period.

NonSlidingUntil is syntactic sugar on top of JitterUntil with zero jitter factor, with sliding = false (meaning the timer for period starts at the same time as the function starts).

func NonSlidingUntilWithContext

func NonSlidingUntilWithContext(ctx context.Context, f func(context.Context), period time.Duration)

NonSlidingUntilWithContext loops until context is done, running f every period.

NonSlidingUntilWithContext is syntactic sugar on top of JitterUntilWithContext with zero jitter factor, with sliding = false (meaning the timer for period starts at the same time as the function starts).

func Poll

func Poll(interval, timeout time.Duration, condition ConditionFunc) error

Poll tries a condition func until it returns true, an error, or the timeout is reached.

Poll always waits the interval before the run of 'condition'. 'condition' will always be invoked at least once.

Some intervals may be missed if the condition takes too long or the time window is too short.

If you want to Poll something forever, see PollInfinite.

func PollImmediate

func PollImmediate(interval, timeout time.Duration, condition ConditionFunc) error

PollImmediate tries a condition func until it returns true, an error, or the timeout is reached.

PollImmediate always checks 'condition' before waiting for the interval. 'condition' will always be invoked at least once.

Some intervals may be missed if the condition takes too long or the time window is too short.

If you want to immediately Poll something forever, see PollImmediateInfinite.

func PollImmediateInfinite

func PollImmediateInfinite(interval time.Duration, condition ConditionFunc) error

PollImmediateInfinite tries a condition func until it returns true or an error

PollImmediateInfinite runs the 'condition' before waiting for the interval.

Some intervals may be missed if the condition takes too long or the time window is too short.

func PollImmediateUntil

func PollImmediateUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error

PollImmediateUntil tries a condition func until it returns true, an error or stopCh is closed.

PollImmediateUntil runs the 'condition' before waiting for the interval. 'condition' will always be invoked at least once.

func PollInfinite

func PollInfinite(interval time.Duration, condition ConditionFunc) error

PollInfinite tries a condition func until it returns true or an error

PollInfinite always waits the interval before the run of 'condition'.

Some intervals may be missed if the condition takes too long or the time window is too short.

func PollUntil

func PollUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error

PollUntil tries a condition func until it returns true, an error or stopCh is closed.

PollUntil always waits interval before the first run of 'condition'. 'condition' will always be invoked at least once.

func RecoverFromPanic

func RecoverFromPanic(err *error)

RecoverFromPanic replaces the specified error with an error containing the original error, and the call tree when a panic occurs. This enables error handlers to handle errors and panics the same way.

func Reduce

func Reduce(err error) error

Reduce will return err or, if err is an Aggregate and only has one item, the first item in the aggregate.

func RequestShutdown

func RequestShutdown() bool

RequestShutdown emulates a received event that is considered as shutdown signal (SIGTERM/SIGINT) This returns whether a handler was notified

func RunServer

func RunServer(
	server *http.Server,
	ln net.Listener,
	shutDownTimeout time.Duration,
	stopCh <-chan struct{},
) <-chan struct{}

RunServer spawns a go-routine continuously serving until the stopCh is closed.

func SetupSignalHandler

func SetupSignalHandler() <-chan struct{}

SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned which is closed on one of these signals. If a second signal is caught, the program is terminated with exit code 1.

func Until

func Until(f func(), period time.Duration, stopCh <-chan struct{})

Until loops until stop channel is closed, running f every period.

Until is syntactic sugar on top of JitterUntil with zero jitter factor and with sliding = true (which means the timer for period starts after the f completes).

func UntilWithContext

func UntilWithContext(ctx context.Context, f func(context.Context), period time.Duration)

UntilWithContext loops until context is done, running f every period.

UntilWithContext is syntactic sugar on top of JitterUntilWithContext with zero jitter factor and with sliding = true (which means the timer for period starts after the f completes).

func WaitFor

func WaitFor(wait WaitFunc, fn ConditionFunc, done <-chan struct{}) error

WaitFor continually checks 'fn' as driven by 'wait'.

WaitFor gets a channel from 'wait()”, and then invokes 'fn' once for every value placed on the channel and once more when the channel is closed. If the channel is closed and 'fn' returns false without error, WaitFor returns ErrWaitTimeout.

If 'fn' returns an error the loop ends and that error is returned. If 'fn' returns true the loop ends and nil is returned.

ErrWaitTimeout will be returned if the 'done' channel is closed without fn ever returning true.

When the done channel is closed, because the golang `select` statement is "uniform pseudo-random", the `fn` might still run one or multiple time, though eventually `WaitFor` will return.

Types

type Aggregate

type Aggregate interface {
	error
	Errors() []error
}

Aggregate represents an object that contains multiple errors, but does not necessarily have singular semantic meaning.

func AggregateGoroutines

func AggregateGoroutines(funcs ...func() error) Aggregate

AggregateGoroutines runs the provided functions in parallel, stuffing all non-nil errors into the returned Aggregate. Returns nil if all the functions complete successfully.

func CreateAggregateFromMessageCountMap

func CreateAggregateFromMessageCountMap(m MessageCountMap) Aggregate

CreateAggregateFromMessageCountMap converts MessageCountMap Aggregate

func Flatten

func Flatten(agg Aggregate) Aggregate

Flatten takes an Aggregate, which may hold other Aggregates in arbitrary nesting, and flattens them all into a single Aggregate, recursively.

func NewAggregate

func NewAggregate(errlist []error) Aggregate

NewAggregate converts a slice of errors into an Aggregate interface, which is itself an implementation of the error interface. If the slice is empty, this returns nil. It will check if any of the element of input error list is nil, to avoid nil pointer panic when call Error().

type Backoff

type Backoff struct {
	// The initial duration.
	Duration time.Duration
	// Duration is multiplied by factor each iteration. Must be greater
	// than or equal to zero.
	Factor float64
	// The amount of jitter applied each iteration. Jitter is applied after
	// cap.
	Jitter float64
	// The number of steps before duration stops changing. If zero, initial
	// duration is always used. Used for exponential backoff in combination
	// with Factor.
	Steps int
	// The returned duration will never be greater than cap *before* jitter
	// is applied. The actual maximum cap is `cap * (1.0 + jitter)`.
	Cap time.Duration
}

Backoff holds parameters applied to a Backoff function.

func (*Backoff) Step

func (b *Backoff) Step() time.Duration

Step returns the next interval in the exponential backoff. This method will mutate the provided backoff.

type BackoffManager

type BackoffManager interface {
	Backoff() Timer
}

BackoffManager manages backoff with a particular scheme based on its underlying implementation. It provides an interface to return a timer for backoff, and caller shall backoff until Timer.C returns. If the second Backoff() is called before the timer from the first Backoff() call finishes, the first timer will NOT be drained. The BackoffManager is supposed to be called in a single-threaded environment.

func NewExponentialBackoffManager

func NewExponentialBackoffManager(initBackoff, maxBackoff, resetDuration time.Duration, backoffFactor, jitter float64, c Clock) BackoffManager

NewExponentialBackoffManager returns a manager for managing exponential backoff. Each backoff is jittered and backoff will not exceed the given max. If the backoff is not called within resetDuration, the backoff is reset. This backoff manager is used to reduce load during upstream unhealthiness.

func NewJitteredBackoffManager

func NewJitteredBackoffManager(duration time.Duration, jitter float64, c Clock) BackoffManager

NewJitteredBackoffManager returns a BackoffManager that backoffs with given duration plus given jitter. If the jitter is negative, backoff will not be jittered.

type Clock

type Clock interface {
	PassiveClock
	After(time.Duration) <-chan time.Time
	NewTimer(time.Duration) Timer
	Sleep(time.Duration)
	NewTicker(time.Duration) Ticker
}

Clock allows for injecting fake or real clocks into code that needs to do arbitrary things based on time.

type ConditionFunc

type ConditionFunc func() (done bool, err error)

ConditionFunc returns true if the condition is satisfied, or an error if the loop should be aborted.

type DialFunc

type DialFunc func(ctx context.Context, network, address string) (net.Conn, error)

DialFunc is a shorthand for signature of net.DialContext.

type Dialer

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

Dialer opens connections through Dial and tracks them.

func NewDialer

func NewDialer(dial DialFunc) *Dialer

NewDialer creates a new Dialer instance.

If dial is not nil, it will be used to create new underlying connections. Otherwise net.DialContext is used.

func (*Dialer) CloseAll

func (d *Dialer) CloseAll()

CloseAll forcibly closes all tracked connections.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial creates a new tracked connection.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext creates a new tracked connection.

type FSErrorHandler

type FSErrorHandler func(err error)

FSErrorHandler is called when a fsnotify error occurs.

type FSEventHandler

type FSEventHandler func(event fsnotify.Event)

FSEventHandler is called when a fsnotify event occurs.

type FSWatcher

type FSWatcher interface {
	// Initializes the watcher with the given watch handlers.
	// Called before all other methods.
	Init(FSEventHandler, FSErrorHandler) error

	// Starts listening for events and errors.
	// When an event or error occurs, the corresponding handler is called.
	Run()

	// Add a filesystem path to watch
	AddWatch(path string) error
}

FSWatcher is a callback-based filesystem watcher abstraction for fsnotify.

func NewFsnotifyWatcher

func NewFsnotifyWatcher() FSWatcher

NewFsnotifyWatcher returns an implementation of FSWatcher that continuously listens for fsnotify events and calls the event handler as soon as an event is received.

type FakeClock

type FakeClock struct {
	FakePassiveClock
	// contains filtered or unexported fields
}

FakeClock implements Clock, but returns an arbitrary time.

func NewFakeClock

func NewFakeClock(t time.Time) *FakeClock

NewFakeClock returns a new FakeClock

func (*FakeClock) After

func (f *FakeClock) After(d time.Duration) <-chan time.Time

After is the Fake version of time.After(d).

func (*FakeClock) HasWaiters

func (f *FakeClock) HasWaiters() bool

HasWaiters returns true if After has been called on f but not yet satisfied (so you can write race-free tests).

func (*FakeClock) NewTicker

func (f *FakeClock) NewTicker(d time.Duration) Ticker

NewTicker returns a new Ticker.

func (*FakeClock) NewTimer

func (f *FakeClock) NewTimer(d time.Duration) Timer

NewTimer is the Fake version of time.NewTimer(d).

func (*FakeClock) SetTime

func (f *FakeClock) SetTime(t time.Time)

SetTime sets the time on a FakeClock.

func (*FakeClock) Sleep

func (f *FakeClock) Sleep(d time.Duration)

Sleep pauses the FakeClock for duration d.

func (*FakeClock) Step

func (f *FakeClock) Step(d time.Duration)

Step moves clock by Duration, notifies anyone that's called After, Tick, or NewTimer

type FakePassiveClock

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

FakePassiveClock implements PassiveClock, but returns an arbitrary time.

func NewFakePassiveClock

func NewFakePassiveClock(t time.Time) *FakePassiveClock

NewFakePassiveClock returns a new FakePassiveClock.

func (*FakePassiveClock) Now

func (f *FakePassiveClock) Now() time.Time

Now returns f's time.

func (*FakePassiveClock) SetTime

func (f *FakePassiveClock) SetTime(t time.Time)

SetTime sets the time on the FakePassiveClock.

func (*FakePassiveClock) Since

func (f *FakePassiveClock) Since(ts time.Time) time.Duration

Since returns time since the time in f.

type Group

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

Group allows to start a group of goroutines and wait for their completion.

func NewGroup

func NewGroup() *Group

func (*Group) Start

func (g *Group) Start(f func())

Start starts f in a new goroutine in the group.

func (*Group) StartWithChannel

func (g *Group) StartWithChannel(stopCh <-chan struct{}, f func(stopCh <-chan struct{}))

StartWithChannel starts f in a new goroutine in the group. stopCh is passed to f as an argument. f should stop when stopCh is available.

func (*Group) StartWithChannelAndErr

func (g *Group) StartWithChannelAndErr(stopCh <-chan struct{}, f func(stopCh <-chan struct{}) error)

StartWithChannel starts f in a new goroutine in the group. stopCh is passed to f as an argument. f should stop when stopCh is available.

func (*Group) StartWithContext

func (g *Group) StartWithContext(ctx context.Context, f func(context.Context))

StartWithContext starts f in a new goroutine in the group. ctx is passed to f as an argument. f should stop when ctx.Done() is available.

func (*Group) Wait

func (g *Group) Wait()

type Info

type Info struct {
	Major string `json:"major"`
	Minor string `json:"minor"`
	Patch string `json:"Path"`
}

Info contains versioning information.

var Version Info

func (Info) String

func (info Info) String() string

type ListenerAndHandler

type ListenerAndHandler struct {
	Listener        net.Listener
	Handler         *restful.Container
	NonGoRestfulMux *restful.Container
}

type Matcher

type Matcher func(error) bool

Matcher is used to match errors. Returns true if the error matches.

type MessageCountMap

type MessageCountMap map[string]int

MessageCountMap contains occurrence for each error message.

type OrangeServer

type OrangeServer struct {

	// MinTLSVersion optionally overrides the minimum TLS version supported.
	MinTLSVersion uint16

	// CipherSuites optionally overrides the list of allowed cipher suites for the server.
	CipherSuites []uint16

	// HTTP2MaxStreamsPerConnection is the limit that the api server imposes on each client.
	HTTP2MaxStreamsPerConnection int

	// Handler holds the handlers being used by this API server
	Listener net.Listener
	Handler  *restful.Container

	// ShutdownDelayDuration allows to block shutdown for some time
	ShutdownDelayDuration time.Duration

	// HandlerChainWaitGroup allows you to wait for all chain handlers finish after the server shutdown.
	HandlerChainWaitGroup *SafeWaitGroup

	// ShutdownTimeout is the timeout used for server shutdown. This specifies the timeout before server
	// gracefully shutdown returns.
	ShutdownTimeout time.Duration
	// contains filtered or unexported fields
}

func MakeServer

func MakeServer(name, port string, handle *restful.Container) *OrangeServer

func (*OrangeServer) AddPostStartHook

func (s *OrangeServer) AddPostStartHook(name string, hook PostStartHookFunc) error

AddPostStartHook allows you to add a PostStartHook.

func (*OrangeServer) AddPostStartHookOrDie

func (s *OrangeServer) AddPostStartHookOrDie(name string, hook PostStartHookFunc)

AddPostStartHookOrDie allows you to add a PostStartHook, but dies on failure

func (*OrangeServer) AddPreShutdownHook

func (s *OrangeServer) AddPreShutdownHook(name string, hook PreShutdownHookFunc) error

AddPreShutdownHook allows you to add a PreShutdownHook.

func (*OrangeServer) AddPreShutdownHookOrDie

func (s *OrangeServer) AddPreShutdownHookOrDie(name string, hook PreShutdownHookFunc)

AddPreShutdownHookOrDie allows you to add a PostStartHook, but dies on failure

func (*OrangeServer) Run

func (s *OrangeServer) Run(opt ...ServerOption) error

func (*OrangeServer) Serve

func (s *OrangeServer) Serve(handler http.Handler, shutdownTimeout time.Duration, stopCh <-chan struct{}) <-chan struct{}

Serve runs the secure http server. It fails only if certificates cannot be loaded or the initial listen call fails. The actual server loop (stoppable by closing stopCh) runs in a go routine, i.e. Serve does not block. It returns a stoppedCh that is closed when all non-hijacked active requests have been processed.

type PassiveClock

type PassiveClock interface {
	Now() time.Time
	Since(time.Time) time.Duration
}

PassiveClock allows for injecting fake or real clocks into code that needs to read the current time but does not support scheduling activity in the future.

type PostStartHookContext

type PostStartHookContext struct {
	// LoopbackClientConfig is a config for a privileged loopback connection to the API server
	StopCh <-chan struct{}
}

PostStartHookContext provides information about this API server to a PostStartHookFunc

type PostStartHookFunc

type PostStartHookFunc func(context PostStartHookContext) error

PostStartHookFunc is a function that is called after the server has started.

type PostStartHookProvider

type PostStartHookProvider interface {
	PostStartHook() (string, PostStartHookFunc, error)
}

PostStartHookProvider is an interface in addition to provide a post start hook for the api server

type PreShutdownHookFunc

type PreShutdownHookFunc func() error

PreShutdownHookFunc is a function that can be added to the shutdown logic.

type RateLimiter

type RateLimiter interface {
	// TryAccept returns true if a token is taken immediately. Otherwise,
	// it returns false.
	TryAccept() bool
	// Accept returns once a token becomes available.
	Accept()
	// Stop stops the rate limiter, subsequent calls to CanAccept will return false
	Stop()
	// QPS returns QPS of this rate limiter
	QPS() float32
	// Wait returns nil if a token is taken before the Context is done.
	Wait(ctx context.Context) error
}

func NewFakeAlwaysRateLimiter

func NewFakeAlwaysRateLimiter() RateLimiter

func NewTokenBucketRateLimiter

func NewTokenBucketRateLimiter(qps float32, burst int) RateLimiter

NewTokenBucketRateLimiter creates a rate limiter which implements a token bucket approach. The rate limiter allows bursts of up to 'burst' to exceed the QPS, while still maintaining a smoothed qps rate of 'qps'. The bucket is initially filled with 'burst' tokens, and refills at a rate of 'qps'. The maximum number of tokens in the bucket is capped at 'burst'.

func NewTokenBucketRateLimiterWithClock

func NewTokenBucketRateLimiterWithClock(qps float32, burst int, c Clock) RateLimiter

NewTokenBucketRateLimiterWithClock is identical to NewTokenBucketRateLimiter but allows an injectable clock, for testing.

type RealClock

type RealClock struct{}

RealClock really calls time.Now()

func (RealClock) After

func (RealClock) After(d time.Duration) <-chan time.Time

After is the same as time.After(d).

func (RealClock) NewTicker

func (RealClock) NewTicker(d time.Duration) Ticker

NewTicker returns a new Ticker.

func (RealClock) NewTimer

func (RealClock) NewTimer(d time.Duration) Timer

NewTimer returns a new Timer.

func (RealClock) Now

func (RealClock) Now() time.Time

Now returns the current time.

func (RealClock) Since

func (RealClock) Since(ts time.Time) time.Duration

Since returns time since the specified timestamp.

func (RealClock) Sleep

func (RealClock) Sleep(d time.Duration)

Sleep pauses the RealClock for duration d.

type Runner

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

Runner is an abstraction to make it easy to start and stop groups of things that can be described by a single function which waits on a channel close to exit.

func NewRunner

func NewRunner(f ...func(stop chan struct{})) *Runner

NewRunner makes a runner for the given function(s). The function(s) should loop until the channel is closed.

func (*Runner) Start

func (r *Runner) Start()

Start begins running.

type SafeWaitGroup

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

SafeWaitGroup must not be copied after first use.

func NewSafeWaitGroup

func NewSafeWaitGroup() *SafeWaitGroup

func (*SafeWaitGroup) Add

func (wg *SafeWaitGroup) Add(delta int) error

Add adds delta, which may be negative, similar to sync.WaitGroup. If Add with a positive delta happens after Wait, it will return error, which prevent unsafe Add.

func (*SafeWaitGroup) Done

func (wg *SafeWaitGroup) Done()

Done decrements the WaitGroup counter.

func (*SafeWaitGroup) Reset

func (wg *SafeWaitGroup) Reset()

Wait blocks until the WaitGroup counter is zero.

func (*SafeWaitGroup) Wait

func (wg *SafeWaitGroup) Wait()

Wait blocks until the WaitGroup counter is zero.

type ServerOption

type ServerOption interface {
	// contains filtered or unexported methods
}

A ServerOption sets options such as credentials, codec and keepalive parameters, etc.

func SetDebug

func SetDebug() ServerOption

func SetDocPath

func SetDocPath(dir string) ServerOption

func SetProtocol

func SetProtocol(p proto) ServerOption

func SetSecure

func SetSecure(dir, ca, pub, key string) ServerOption

type Ticker

type Ticker interface {
	C() <-chan time.Time
	Stop()
}

Ticker defines the Ticker interface

type Timer

type Timer interface {
	C() <-chan time.Time
	Stop() bool
	Reset(d time.Duration) bool
}

Timer allows for injecting fake or real timers into code that needs to do arbitrary things based on time.

type WaitFunc

type WaitFunc func(done <-chan struct{}) <-chan struct{}

WaitFunc creates a channel that receives an item every time a test should be executed and is closed when the last test should be invoked.

Directories

Path Synopsis
Package sets has auto-generated set types.
Package sets has auto-generated set types.
types
Package types just provides input types to the set generator.
Package types just provides input types to the set generator.

Jump to

Keyboard shortcuts

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