service

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package service contains an example of a production-like gRPC service for integration tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildExternalServiceChain

func BuildExternalServiceChain(orderID string, amount int64) []string

BuildExternalServiceChain builds an outbound-call sequence from order data.

For standard orders, two calls are executed: 1) risk:<order-id> 2) reserve:<order-id>

For large orders, a third call is added: 3) manual:<order-id>.

func IsOrderNotFoundError

func IsOrderNotFoundError(err error) bool

IsOrderNotFoundError returns true when error indicates a missing order.

Types

type APIServer

type APIServer struct {
	grpc_health_v1.UnimplementedHealthServer
	// contains filtered or unexported fields
}

APIServer simulates a real service gRPC API.

Input: - request.service = order_id

Behavior: 1) reads an order from repository; 2) builds external call chain; 3) makes outbound gRPC calls to external API; 4) stores final result in repository; 5) returns final status.

func NewAPIServer

func NewAPIServer(
	repository orderRepository,
	externalClient grpc_health_v1.HealthClient,
) *APIServer

NewAPIServer creates the service API server.

func (*APIServer) Check

Check processes an inbound API request and executes external calls.

type InMemoryOrderRepository

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

InMemoryOrderRepository stores orders in memory and is used in integration tests.

func NewInMemoryOrderRepository

func NewInMemoryOrderRepository() *InMemoryOrderRepository

NewInMemoryOrderRepository creates an empty in-memory repository.

func (*InMemoryOrderRepository) Get

func (repository *InMemoryOrderRepository) Get(_ context.Context, orderID string) (Order, error)

Get returns an order by ID.

func (*InMemoryOrderRepository) Save

func (repository *InMemoryOrderRepository) Save(_ context.Context, order Order) error

Save stores an order in the repository.

func (*InMemoryOrderRepository) UpdateProcessingResult

func (repository *InMemoryOrderRepository) UpdateProcessingResult(
	_ context.Context,
	orderID string,
	status grpc_health_v1.HealthCheckResponse_ServingStatus,
	externalServices []string,
) error

UpdateProcessingResult updates order status and outbound-call log.

type Order

type Order struct {
	ID               string
	Amount           int64
	Status           grpc_health_v1.HealthCheckResponse_ServingStatus
	ExternalServices []string
}

Order stores order state in an in-memory repository.

Jump to

Keyboard shortcuts

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