server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server is partner-emulator: the stand's trading partner that receives the documents the gateway sends and answers them the way a real partner does.

Input: POST /as2 with an X12 interchange (an 855, a 856 or the 997 of the gateway) and the headers AS2-From (the gateway), AS2-To (this partner) and Message-Id. Output: the MDN as JSON, and later, asynchronously, a 997 posted to the gateway's /edi/inbound with the token of this partner. Every transmission is parsed with the strict parser of the gateway (internal/edi/x12) and written to mock_partner.received, also a repeat with the same ISA13: a test counts the different ISA13 values to see how many documents the partner really got.

Several gateway processes may share one emulator (the slots of the benchmark). A process names itself in the header Edigate-Reply-To of /as2; its 997 goes to that address with the token of "<address> <partner id>" in the tokens file (else "<partner id>"). Without the header the 997 goes to GATEWAY_URL.

The emulator is also the mail service of the stand: POST /email takes a letter as a template id, an address and an order number, makes the text itself and writes a row with kind = 'email' (once per external_id); GET /email?external_id= says whether it is there.

The behaviour is set by knobs that tests and the stand change at run time with POST /control (only from the stand's own addresses: loopback and private networks): the delay and the verdict of the 997 (A, E, R, P with mixed verdicts, none), the delay of the MDN and the share of transmissions that get no MDN.

Index

Constants

View Source
const ReplyToHeader = "Edigate-Reply-To"

ReplyToHeader is the stand header in which a gateway process says where its 997 must be posted: its own public address. Without it the 997 goes to GATEWAY_URL. Several processes of the gateway (the slots of the benchmark) share this emulator, and each gets its own.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool) error

Migrate creates the schema, the table and the counter of the emulator if they are missing. tenant_id of a row is the id the gateway sent under (AS2-From), because the partner does not know tenants; partner_id is the id of this partner (AS2-To).

Types

type Config

type Config struct {
	Knobs
	GatewayURL string // where the 997 goes: <GatewayURL>/edi/inbound
	TokensFile string // JSON {"<partner id>": "<token>"}, read again at every send
	Log        *slog.Logger
}

Config is what the emulator needs to start.

type Knobs

type Knobs struct {
	AckDelayMS  int     `json:"ack_delay_ms"` // PARTNER_ACK_DELAY_MS
	AckStatus   string  `json:"ack_status"`   // PARTNER_ACK_STATUS: A, E, R, P or none
	MDNDelayMS  int     `json:"mdn_delay_ms"` // PARTNER_MDN_DELAY_MS
	MDNDropRate float64 `json:"mdn_drop"`     // PARTNER_MDN_DROP: share of transmissions without an MDN, 0 to 1
}

Knobs are the settings that change the behaviour. The JSON names are those of POST /control.

func (Knobs) Valid

func (k Knobs) Valid() bool

Valid reports whether the knobs are in range.

type Server

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

Server is the HTTP handler of the emulator.

func New

func New(pool *pgxpool.Pool, cfg Config) *Server

New builds the server on a pool whose database has the schema (see Migrate).

func (*Server) Close

func (s *Server) Close()

Close waits for the 997 that are on their way.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the routes of the emulator.

Jump to

Keyboard shortcuts

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