util

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package util holds various utility functions used throughout the Trillian codebase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AwaitSignal

func AwaitSignal(ctx context.Context, doneFn func())

AwaitSignal waits for standard termination signals, then runs the given function. Can early return if the passed in context is canceled, in which case the function is not run.

func SecondsSince added in v1.0.7

func SecondsSince(ts TimeSource, t time.Time) float64

SecondsSince returns the time in seconds elapsed since t until now, as measured by the TimeSource.

func Sleep added in v1.2.0

func Sleep(done <-chan struct{}, dur time.Duration) bool

Sleep sleeps for at least the specified duration. Returns false iff done is closed before the timer fires.

func SleepContext added in v1.2.0

func SleepContext(ctx context.Context, dur time.Duration) error

SleepContext sleeps for at least the specified duration. Returns ctx.Err() iff the context is canceled before the timer fires.

func StartHTTPServer

func StartHTTPServer(addr, certFile, keyFile string) error

StartHTTPServer starts an HTTP server on the given address.

Types

type FakeTimeSource

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

FakeTimeSource provides a time that can be any arbitrarily set value for use in tests. It should not be used in production code.

func NewFakeTimeSource

func NewFakeTimeSource(t time.Time) *FakeTimeSource

NewFakeTimeSource creates a FakeTimeSource instance

func (*FakeTimeSource) Now

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

Now returns the time value this instance contains

func (*FakeTimeSource) Set

func (f *FakeTimeSource) Set(t time.Time)

Set gives the time that this instance will report

type IncrementingFakeTimeSource

type IncrementingFakeTimeSource struct {
	BaseTime      time.Time
	Increments    []time.Duration
	NextIncrement int
}

IncrementingFakeTimeSource takes a base time and several increments, which will be applied to the base time each time Now() is called. The first call will return the base time + zeroth increment. If called more times than provided for then it will panic. Does not require that increments increase monotonically.

func (*IncrementingFakeTimeSource) Now

Now returns the current time according to this time source, which depends on how many times this method has already been invoked.

type SystemTimeSource

type SystemTimeSource struct{}

SystemTimeSource provides the current system local time

func (SystemTimeSource) Now

func (s SystemTimeSource) Now() time.Time

Now returns the true current local time.

type TimeSource

type TimeSource interface {
	// Now returns the current time in real implementations or a suitable value in others
	Now() time.Time
}

TimeSource can provide the current time, or be replaced by a mock in tests to return specific values.

Directories

Path Synopsis
Package election provides implementation of master election and tracking, as well as interface for plugging in a custom underlying mechanism.
Package election provides implementation of master election and tracking, as well as interface for plugging in a custom underlying mechanism.
stub
Package stub contains a MasterElection implementation for testing.
Package stub contains a MasterElection implementation for testing.
Package etcd holds an etcd-specific implementation of the util.MasterElection interface.
Package etcd holds an etcd-specific implementation of the util.MasterElection interface.
Package flagsaver provides a simple way to save and restore flag values.
Package flagsaver provides a simple way to save and restore flag values.
Package proxy forwards Trillian Log Server requests to another server.
Package proxy forwards Trillian Log Server requests to another server.

Jump to

Keyboard shortcuts

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