util

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextRoundTripper

func ContextRoundTripper(ctx context.Context, rt http.RoundTripper) http.RoundTripper

ContextRoundTripper will return an http.RoundTripper that will replace all request contexts with the provided one. This means that values and deadlines for all requests will be bound to the original context.

func JoinURL

func JoinURL(base, suffix string) (string, error)

JoinURL will join a base URL and suffix, taking care to preserve and merge query parameters.

func LoadLocation

func LoadLocation(name string) (*time.Location, error)

LoadLocation works like time.LoadLocation but caches the result for the life of the process.

func WrapCacheableContext

func WrapCacheableContext(next http.Handler) http.Handler

WrapCacheableContext will make all request contexts cacheable, to be used with a ContextCache.

Types

type AlignedTicker

type AlignedTicker struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

AlignedTicker works like a time.Ticker except it will align the first tick. This makes it useful in situations where something should run on-the-minute for example.

func NewAlignedTicker

func NewAlignedTicker(round, variance time.Duration) *AlignedTicker

NewAlignedTicker will create and start a new AlignedTicker. The first tick will be adjusted to round, with variance added.

For example (time.Minute, time.Second) will align ticks to on-the-minute plus 0-1 second.

func (*AlignedTicker) Stop

func (a *AlignedTicker) Stop()

Stop will stop the running ticker and close the channel.

type ContextCache

type ContextCache interface {
	Load(ctx context.Context, id string) interface{}
	Store(ctx context.Context, id string, value interface{})
	LoadOrStore(context.Context, string, func() (interface{}, error)) (interface{}, error)
}

A ContextCache is used to cache and load values on a per-context basis. No values will be stored unless the context.Context has passed through WrapCacheableContext.

func NewContextCache

func NewContextCache() ContextCache

NewContextCache creates a new ContextCache

type ContextPreparer

type ContextPreparer interface {
	PrepareContext(context.Context, string) (*sql.Stmt, error)
}

type ContextWaitGroup

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

func NewContextWaitGroup

func NewContextWaitGroup(ctx context.Context) *ContextWaitGroup

func (*ContextWaitGroup) Add

func (c *ContextWaitGroup) Add(n int)

func (*ContextWaitGroup) Done

func (c *ContextWaitGroup) Done()

func (*ContextWaitGroup) Wait

func (c *ContextWaitGroup) Wait()

func (*ContextWaitGroup) WaitCh

func (c *ContextWaitGroup) WaitCh() <-chan struct{}

type Prepare

type Prepare struct {
	DB  Preparer
	Ctx context.Context
	Err error
}

Prepare is used to prepare SQL statements.

If Ctx is specified, it will be used to prepare all statements. Only the first error is recorded. Subsequent calls to `P` are ignored after a failure.

func (*Prepare) P

func (p *Prepare) P(query string) (s *sql.Stmt)

type PrepareStmt

type PrepareStmt struct {
	*sql.Stmt
	// contains filtered or unexported fields
}

func (*PrepareStmt) PrepareFor

func (p *PrepareStmt) PrepareFor(ctx context.Context, cp ContextPreparer) (*sql.Stmt, error)

type Preparer

type Preparer interface {
	PrepareContext(context.Context, string) (*sql.Stmt, error)
}

type QueryError

type QueryError interface {
	Query() string
	Cause() *sqlutil.Error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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