Help us shape the future of Go! Take the 2026 Go Developer Survey

clock

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package clock is the canonical injected-dependency example (ADR-0002). It provides the Clock interface so components can be tested with a deterministic fake instead of wall-clock time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock is the port for time operations. Components depend on this interface; the app injects System() in production and a Fake in tests.

func Fake

func Fake(t time.Time) Clock

Fake returns a clock fixed at the given time — useful for deterministic tests.

func System

func System() Clock

System returns the real-time clock.

type Manual added in v0.2.5

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

Manual is a fake clock that stands still until Advance moves it, for tests of time-bounded behavior. Safe for concurrent use.

func NewManual added in v0.2.5

func NewManual(t time.Time) *Manual

NewManual returns a Manual clock standing at t.

func (*Manual) Advance added in v0.2.5

func (m *Manual) Advance(d time.Duration)

Advance moves the clock forward by d.

func (*Manual) Now added in v0.2.5

func (m *Manual) Now() time.Time

Now returns the clock's current time.

Jump to

Keyboard shortcuts

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