Documentation
¶
Overview ¶
Package phorm is a Go HTTP client for a phorm (https://github.com/phax/phorm) business-document validation service. It replaces the gRPC client of the invopop/phive service; the request/response types keep the same exported field names so callers migrate by swapping only the constructor.
Index ¶
Constants ¶
const ( // DefaultToken is phorm's built-in default X-Token. phorm always requires a // matching non-empty token and cannot disable auth, but when it is only // reachable inside a trusted network the token is not a security boundary, so // New falls back to this when no token is supplied. DefaultToken = "phorm-dev-token" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to a phorm validation service over HTTP.
func New ¶
New creates a phorm client for the service at baseURL (e.g. "http://phorm:8080") authenticating with the given X-Token value. An empty token falls back to DefaultToken, so callers pointing at a phorm that uses the stock token need not configure one.
func (*Client) ListVesIds ¶
func (c *Client) ListVesIds(ctx context.Context, req *ListVesIdsRequest) (*ListVesIdsResponse, error)
ListVesIds lists the available VESIDs via GET /api/get/vesids. req.Filter, if set, is applied client-side (phorm has no server-side filter).
func (*Client) ValidateXml ¶
func (c *Client) ValidateXml(ctx context.Context, req *ValidateXmlRequest) (*ValidateXmlResponse, error)
ValidateXml validates req.XmlContent against req.Vesid via POST /api/validate/{vesid}.
phorm answers a document that breaks a rule with HTTP 400 and the validation report as the body, so the status code alone cannot tell a failed validation from a rejected request: an unresolvable VESID and a body that is not XML are also 400, and a bad token is 403. What separates them is the body, which is the JSON report only when the validation actually ran.
A report is therefore returned as a response whatever the status, with the findings in resp.Results and resp.Success reporting the outcome. A non-nil error means the request never produced a report — the service is unreachable, the token was rejected, the VESID could not be resolved, or the document was not readable as XML.
type ListVesIdsRequest ¶
type ListVesIdsRequest struct {
// Filter, when non-empty, keeps only VESIDs whose id or name contains it
// (case-insensitive). phorm has no server-side filter, so it is applied
// client-side.
Filter string
}
ListVesIdsRequest is a request to list the available VESIDs.
type ListVesIdsResponse ¶
ListVesIdsResponse contains the list of available VESIDs.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient overrides the underlying *http.Client (e.g. to set a custom timeout or transport).
type ValidateXmlRequest ¶
type ValidateXmlRequest struct {
// Vesid is sent as the {vesid} path segment of POST /api/validate/{vesid}.
Vesid string
// XmlContent is the raw XML request body.
XmlContent []byte
// SourceIdentifier is retained for caller-side logging only; phorm's
// validate endpoint does not accept it.
SourceIdentifier string
}
ValidateXmlRequest is a request to validate an XML document.
type ValidateXmlResponse ¶
type ValidateXmlResponse struct {
Success bool
// ResolvedVesid is populated from phorm's `ves.vesid` when present.
ResolvedVesid string
Results []*ValidationLayerResult
// ErrorMessage carries an execution-level error. With phorm these arrive as
// non-2xx HTTP responses and are returned as a Go error instead, so this is
// normally empty.
ErrorMessage string
Timestamp string
}
ValidateXmlResponse is the result of a validation.
type ValidationError ¶
type ValidationError struct {
// Level is "ERROR", "WARN", etc. (phorm's `errorLevel`).
Level string
// ErrorID is the rule identifier (phorm's `errorID`), e.g. "UBL-CR-397".
ErrorID string
// Message is phorm's `errorText`.
Message string
// Location is a human-readable "line N, col M" from phorm's `errorLocationObj`.
Location string
// Xpath is phorm's `errorFieldName`.
Xpath string
// TestId is the schematron rule id (phorm's `test`).
TestId string
Details map[string]string
}
ValidationError is a single error or warning item.
type ValidationLayerResult ¶
type ValidationLayerResult struct {
// ValidationType is mapped from phorm's `artifactType`.
ValidationType string
// ArtifactId is mapped from phorm's `artifactPath`.
ArtifactId string
Success bool
Errors []*ValidationError
Warnings []*ValidationError
}
ValidationLayerResult holds the outcome of a single validation layer/artifact.