Explain the Go consumer API contracts - #110
Merged
Merged
Conversation
Document how callers distinguish top-level errors, failed assertions, and evaluation errors. Add examples for structured outcome handling, custom HTTP policy, response-body ownership, and the package's pre-v1 compatibility policy. Co-Authored-By: OpenAI Codex (GPT-5) <noreply@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Go consumers lack enough documentation to handle structured outcomes, customize request policy, or understand response-body ownership safely.
The existing README names these concepts but does not show how their contracts fit together. Callers must infer when a top-level error can carry a partial result, how failures differ from evaluation errors, which values are safe to switch on, and whether the response body remains readable.
Solution
Document the complete consumer contract with copyable, executable examples for outcomes, HTTP policy, body access, and version compatibility.
flowchart TD Do["ha.Client.Do"] -->|"top-level error"| Incomplete["no complete outcome set; Result may be partial"] Do -->|"nil error"| Result["one Outcome per assertion"] Result --> Pass["Passed: assertion held"] Result --> Failure["Failure: response disproved assertion"] Result --> Evaluation["Err: assertion could not reach a verdict"]The result example uses exported kind and error-code constants, handles
*ha.EvaluationErrorwitherrors.As, and preserves a fallback for errors returned by custom assertions. The HTTP-policy example demonstrates caller context and client timeouts without moving retry or presentation policy into the library.The ownership section states that
Client.Doconsumes and closes the original body, while decoded bytes and HTTP metadata remain on the structured response. A compatibility section sets the expected pre-v1 upgrade contract.No visual change: this updates README and Go package documentation.
Other Changes
ha.Related:
🤖 Generated with Claude Code