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 ¶
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 ¶
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 ¶
func (server *APIServer) Check( ctx context.Context, request *grpc_health_v1.HealthCheckRequest, ) (*grpc_health_v1.HealthCheckResponse, error)
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) 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.