calculator

package
v1.22.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Hostname = calculatorapi.Hostname
	Version  = 352
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Intermediate added in v1.22.0

type Intermediate struct {
	*connector.Connector
	ToDo
}

Intermediate extends and customizes the generic base connector.

func NewIntermediate added in v1.22.0

func NewIntermediate(impl ToDo) *Intermediate

NewIntermediate creates a new instance of the intermediate.

func (*Intermediate) IncrementUsedOperators added in v1.22.0

func (svc *Intermediate) IncrementUsedOperators(ctx context.Context, num int, op string) (err error)

IncrementUsedOperators counts the types of the arithmetic operators used.

func (*Intermediate) RecordSumOperations added in v1.22.0

func (svc *Intermediate) RecordSumOperations(ctx context.Context, sum int, op string) (err error)

RecordSumOperations records the total sum of the results of all operators.

type Mock

type Mock struct {
	*Intermediate
	// contains filtered or unexported fields
}

Mock is a mockable version of the microservice, allowing functions, event sinks and web handlers to be mocked.

func NewMock

func NewMock() *Mock

NewMock creates a new mockable version of the microservice.

func (*Mock) Arithmetic added in v1.22.0

func (svc *Mock) Arithmetic(ctx context.Context, x int, op string, y int) (xEcho int, opEcho string, yEcho int, result int, err error)

Arithmetic executes the mock handler.

func (*Mock) Distance added in v1.22.0

func (svc *Mock) Distance(ctx context.Context, p1 calculatorapi.Point, p2 calculatorapi.Point) (d float64, err error)

Distance executes the mock handler.

func (*Mock) MockArithmetic added in v1.22.0

func (svc *Mock) MockArithmetic(handler func(ctx context.Context, x int, op string, y int) (xEcho int, opEcho string, yEcho int, result int, err error)) *Mock

MockArithmetic sets up a mock handler for Arithmetic.

func (*Mock) MockDistance added in v1.22.0

func (svc *Mock) MockDistance(handler func(ctx context.Context, p1 calculatorapi.Point, p2 calculatorapi.Point) (d float64, err error)) *Mock

MockDistance sets up a mock handler for Distance.

func (*Mock) MockOnObserveSumOperations added in v1.22.0

func (svc *Mock) MockOnObserveSumOperations(handler func(ctx context.Context) (err error)) *Mock

MockOnObserveSumOperations sets up a mock handler for OnObserveSumOperations.

func (*Mock) MockSquare added in v1.22.0

func (svc *Mock) MockSquare(handler func(ctx context.Context, x int) (xEcho int, result int, err error)) *Mock

MockSquare sets up a mock handler for Square.

func (*Mock) OnObserveSumOperations added in v1.22.0

func (svc *Mock) OnObserveSumOperations(ctx context.Context) (err error)

OnObserveSumOperations executes the mock handler.

func (*Mock) OnShutdown added in v1.22.0

func (svc *Mock) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Mock) OnStartup added in v1.22.0

func (svc *Mock) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Mock) Square added in v1.22.0

func (svc *Mock) Square(ctx context.Context, x int) (xEcho int, result int, err error)

Square executes the mock handler.

type Service

type Service struct {
	*Intermediate // IMPORTANT: Do not remove
	// contains filtered or unexported fields
}

Service implements the calculator.example microservice.

The Calculator microservice performs simple mathematical operations.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) Arithmetic

func (svc *Service) Arithmetic(ctx context.Context, x int, op string, y int) (xEcho int, opEcho string, yEcho int, result int, err error)

Arithmetic perform an arithmetic operation between two integers x and y given an operator op.

func (*Service) Distance

func (svc *Service) Distance(ctx context.Context, p1 calculatorapi.Point, p2 calculatorapi.Point) (d float64, err error)

Distance calculates the distance between two points. It demonstrates the use of the defined type Point.

func (*Service) Init

func (svc *Service) Init(initializer func(svc *Service) (err error)) *Service

Init enables a single-statement pattern for initializing the microservice.

func (*Service) OnObserveSumOperations added in v1.13.1

func (svc *Service) OnObserveSumOperations(ctx context.Context) (err error)

OnObserveSumOperations observes the value of the SumOperations gauge metric. SumOperations tracks the total sum of the results of all operators.

func (*Service) OnShutdown

func (svc *Service) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Service) OnStartup

func (svc *Service) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Service) Square

func (svc *Service) Square(ctx context.Context, x int) (xEcho int, result int, err error)

Square prints the square of the integer x.

type ToDo added in v1.22.0

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	OnObserveSumOperations(ctx context.Context) (err error)                                                               // MARKER: SumOperations
	Arithmetic(ctx context.Context, x int, op string, y int) (xEcho int, opEcho string, yEcho int, result int, err error) // MARKER: Arithmetic
	Square(ctx context.Context, x int) (xEcho int, result int, err error)                                                 // MARKER: Square
	Distance(ctx context.Context, p1 calculatorapi.Point, p2 calculatorapi.Point) (d float64, err error)                  // MARKER: Distance
}

ToDo is implemented by the service or mock. The intermediate delegates handling to this interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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