package util

import "github.com/google/trillian/util"

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

Index

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

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

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

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.

Source Files

doc.go process.go time.go timesource.go

Directories

PathSynopsis
util/electionPackage election provides implementation of master election and tracking, as well as interface for plugging in a custom underlying mechanism.
util/election/stubPackage stub contains a MasterElection implementation for testing.
util/etcdPackage etcd holds an etcd-specific implementation of the util.MasterElection interface.
util/flagsaverPackage flagsaver provides a simple way to save and restore flag values.
util/proxyPackage proxy forwards Trillian Log Server requests to another server.
Version
v1.2.1
Published
Aug 16, 2018
Platform
js/wasm
Imports
9 packages
Last checked
4 hours ago

Tools for package owners.