calculatorapi

package
v1.41.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const Description = `The Calculator microservice performs simple mathematical operations.`

Description is the human-readable summary of the microservice, surfaced in OpenAPI and discovery.

View Source
const Hostname = "calculator.example"

Hostname is the default hostname of the microservice.

View Source
const Name = "Calculator"

Name is the decorative PascalCase name of the microservice.

View Source
const Version = 353

Version is a generation counter bumped on each regeneration, not a semantic version.

Variables

View Source
var Arithmetic = define.Function{
	Host: Hostname, Method: "GET", Route: ":443/arithmetic",
	In: ArithmeticIn{}, Out: ArithmeticOut{},
}

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

View Source
var Distance = define.Function{
	Host: Hostname, Method: "ANY", Route: ":443/distance",
	In: DistanceIn{}, Out: DistanceOut{},
}

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

View Source
var Square = define.Function{
	Host: Hostname, Method: "GET", Route: ":443/square",
	In: SquareIn{}, Out: SquareOut{},
}

Square prints the square of the integer x.

View Source
var SumOperations = define.Metric{
	Kind: define.Gauge, Value: int(0), Labels: []string{"op"},
	OTelName: "sum_operations", Observable: true,
}

SumOperations tracks the total sum of the results of all operators.

View Source
var UsedOperators = define.Metric{
	Kind: define.Counter, Value: int(0), Labels: []string{"op"},
	OTelName: "used_operators",
}

UsedOperators tracks the types of the arithmetic operators used.

Functions

This section is empty.

Types

type ArithmeticIn

type ArithmeticIn struct {
	X  int    `json:"x,omitzero" jsonschema_description:"X is the left operand"`
	Op string `json:"op,omitzero" jsonschema_description:"Op is the operator: + - * /"`
	Y  int    `json:"y,omitzero" jsonschema_description:"Y is the right operand"`
}

ArithmeticIn are the input arguments of Arithmetic.

type ArithmeticOut

type ArithmeticOut struct {
	XEcho  int    `json:"xEcho,omitzero" jsonschema_description:"XEcho echoes the left operand"`
	OpEcho string `json:"opEcho,omitzero" jsonschema_description:"OpEcho echoes the operator"`
	YEcho  int    `json:"yEcho,omitzero" jsonschema_description:"YEcho echoes the right operand"`
	Result int    `json:"result,omitzero" jsonschema_description:"Result is the result of the operation"`
}

ArithmeticOut are the output arguments of Arithmetic.

type ArithmeticResponse

type ArithmeticResponse multicastResponse // MARKER: Arithmetic

ArithmeticResponse packs the response of Arithmetic.

func (*ArithmeticResponse) Get

func (_res *ArithmeticResponse) Get() (xEcho int, opEcho string, yEcho int, result int, err error)

Get unpacks the return arguments of Arithmetic.

type Client

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

Client is a lightweight proxy for making unicast calls to the microservice.

func NewClient

func NewClient(caller service.Publisher) Client

NewClient creates a new unicast client proxy to the microservice.

func (Client) Arithmetic

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

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

func (Client) Distance

func (_c Client) Distance(ctx context.Context, p1 Point, p2 Point) (d float64, err error)

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

func (Client) ForHost

func (_c Client) ForHost(host string) Client

ForHost returns a copy of the client with a different hostname to be applied to requests.

func (Client) Square

func (_c Client) Square(ctx context.Context, x int) (xEcho int, result int, err error)

Square prints the square of the integer x.

func (Client) WithOptions added in v1.13.1

func (_c Client) WithOptions(opts ...pub.Option) Client

WithOptions returns a copy of the client with options to be applied to requests.

type DistanceIn

type DistanceIn struct {
	P1 Point `json:"p1,omitzero" jsonschema_description:"P1 is the first point"`
	P2 Point `json:"p2,omitzero" jsonschema_description:"P2 is the second point"`
}

DistanceIn are the input arguments of Distance.

type DistanceOut

type DistanceOut struct {
	D float64 `json:"d,omitzero" jsonschema_description:"D is the Euclidean distance between P1 and P2"`
}

DistanceOut are the output arguments of Distance.

type DistanceResponse

type DistanceResponse multicastResponse // MARKER: Distance

DistanceResponse packs the response of Distance.

func (*DistanceResponse) Get

func (_res *DistanceResponse) Get() (d float64, err error)

Get unpacks the return arguments of Distance.

type MulticastClient

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

MulticastClient is a lightweight proxy for making multicast calls to the microservice.

func NewMulticastClient

func NewMulticastClient(caller service.Publisher) MulticastClient

NewMulticastClient creates a new multicast client proxy to the microservice.

func (MulticastClient) Arithmetic

func (_c MulticastClient) Arithmetic(ctx context.Context, x int, op string, y int) iter.Seq[*ArithmeticResponse]

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

func (MulticastClient) Distance

func (_c MulticastClient) Distance(ctx context.Context, p1 Point, p2 Point) iter.Seq[*DistanceResponse]

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

func (MulticastClient) ForHost

func (_c MulticastClient) ForHost(host string) MulticastClient

ForHost returns a copy of the client with a different hostname to be applied to requests.

func (MulticastClient) Square

Square prints the square of the integer x.

func (MulticastClient) WithOptions added in v1.13.1

func (_c MulticastClient) WithOptions(opts ...pub.Option) MulticastClient

WithOptions returns a copy of the client with options to be applied to requests.

type Point

type Point struct {
	X float64 `json:"x,omitzero" jsonschema_description:"X coordinate" jsonschema:"example=6"`
	Y float64 `json:"y,omitzero" jsonschema_description:"Y coordinate" jsonschema:"example=8"`
}

Point is a 2D (X,Y) coordinate.

type SquareIn

type SquareIn struct {
	X int `json:"x,omitzero" jsonschema_description:"X is the integer to square"`
}

SquareIn are the input arguments of Square.

type SquareOut

type SquareOut struct {
	XEcho  int `json:"xEcho,omitzero" jsonschema_description:"XEcho echoes the input integer"`
	Result int `json:"result,omitzero" jsonschema_description:"Result is X squared"`
}

SquareOut are the output arguments of Square.

type SquareResponse

type SquareResponse multicastResponse // MARKER: Square

SquareResponse packs the response of Square.

func (*SquareResponse) Get

func (_res *SquareResponse) Get() (xEcho int, result int, err error)

Get unpacks the return arguments of Square.

Jump to

Keyboard shortcuts

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