timeoracle

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SimpleTimeOracle

type SimpleTimeOracle struct {
	// Address is the IP address of the time oracle.
	Address string
	// Port is the port number of the time oracle.
	Port int

	// MsgChan is the channel used for sending and receiving messages.
	MsgChan chan string
	// contains filtered or unexported fields
}

SimpleTimeOracle represents a simple time oracle that provides time-related information. It contains the address, port, base URL, server, message channel, and locker.

func NewSimpleTimeOracle

func NewSimpleTimeOracle(address string, port int, locker locker.Locker) *SimpleTimeOracle

NewSimpleTimeOracle creates a new instance of SimpleTimeOracle.

func (*SimpleTimeOracle) GetTime

func (s *SimpleTimeOracle) GetTime() time.Time

GetTime returns the current time as reported by the SimpleTimeOracle.

func (*SimpleTimeOracle) Start

func (s *SimpleTimeOracle) Start() error

Start starts the SimpleTimeOracle server. It initializes the router and sets up the necessary routes for serving time, locking, and unlocking. It then starts the server and listens for incoming requests. Returns an error if there was a problem starting the server.

func (*SimpleTimeOracle) Stop

func (s *SimpleTimeOracle) Stop() error

Stop stops the SimpleTimeOracle server gracefully. It shuts down the server and sends a message to the MsgChan indicating that the Simple Time Oracle has stopped. It returns an error if there was an issue shutting down the server.

func (*SimpleTimeOracle) WaitForStartUp

func (s *SimpleTimeOracle) WaitForStartUp(timeout time.Duration) error

WaitForStartUp waits for the server to start up by continuously sending HTTP requests to the "/time" endpoint until a successful response is received or the timeout is reached. It returns an error if the server does not reply within the specified timeout duration.

type TimeOracle

type TimeOracle interface {
	GetTime() time.Time
}

TimeOracle is an interface that defines a method for retrieving the current time.

Jump to

Keyboard shortcuts

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