util

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateRefreshBuffer

func CalculateRefreshBuffer(timeUntilExpiry time.Duration) time.Duration

CalculateRefreshBuffer calculates how long before credential expiry we should refresh. It returns 20% of the time until expiry, with a minimum of 1 minute and maximum of 5 minutes. A random jitter of up to 10% is added to prevent thundering herd issues.

func RunFuncAtInterval

func RunFuncAtInterval(ctx context.Context, interval time.Duration, f func(context.Context) error)

func RunFuncAtIntervalWithErrorHandler

func RunFuncAtIntervalWithErrorHandler(ctx context.Context, interval time.Duration, f func(context.Context) error, errorHandler func(err error) error) error

func SendErrorToChannel added in v0.3.0

func SendErrorToChannel(credsChan chan credential.Result, err error)

SendErrorToChannel is a helper function to send an error result to the credentials channel.

func SendToChannel

func SendToChannel(credsChan chan credential.Result, result credential.Result)

SendToChannel writes the credential.Result to the channel, ensuring the latest result is always available.

Types

type ContextHolder added in v0.4.0

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

ContextHolder atomically stores a context.Context that can be set from one goroutine and read from another, for smuggling a context through third-party interfaces that don't accept one as a parameter.

func (*ContextHolder) Context added in v0.4.0

func (h *ContextHolder) Context() context.Context

Context returns the context last passed to Store, or context.Background() if Store has never been called.

func (*ContextHolder) Store added in v0.4.0

func (h *ContextHolder) Store(ctx context.Context)

Store sets the context returned by subsequent calls to Context.

type SyncGate

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

SyncGate is a synchronization primitive that can be opened and closed. When open, calls to Wait will return immediately. When closed, calls to Wait will block until it is opened.

func NewSyncGate

func NewSyncGate() *SyncGate

NewSyncGate creates a new SyncGate, initially closed

func (*SyncGate) Close

func (g *SyncGate) Close()

Close makes a new channel, blocking future waiters

func (*SyncGate) IsOpen

func (g *SyncGate) IsOpen() bool

IsOpen returns true if the gate is open

func (*SyncGate) Open

func (g *SyncGate) Open()

Open closes the channel, unblocking waiters

func (*SyncGate) Wait

func (g *SyncGate) Wait(ctx context.Context) error

Wait waits until the gate is open, or context is done

Jump to

Keyboard shortcuts

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