conduit

package
v0.3.0-20261125210437-... Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 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.

README

Conduit client

Conduit is Phabricator's HTTP API. This package is the one way SubmitQueue code calls it: it encodes a method's parameters, authenticates the call, and turns Conduit's reply into either the caller's typed result or a typed error. It holds a single generic Call and no per-method wrappers.

Setting it up

Build the client once in wiring and share it; it is safe for concurrent use.

  • Start from an *http.Client whose transport resolves relative paths against the Phabricator host (platform/http.NewClient(endpoint) installs a BaseURLTransport). That client owns the timeout and connection limits.
  • Wrap it with NewClient(httpClient, token), where token is a Conduit API token. One client serves one host and one token.

The package never reads configuration or credentials itself.

What a call sends

Call(ctx, method, params, result) posts a form to /api/<method> with two fields:

  • params: the caller's parameters as a JSON object, with the token added under __conduit__. Parameters may be a map or a struct, or nil for none; anything that does not encode as a JSON object is rejected before a request is sent.
  • output: json.

The context bounds the request, so cancelling it or hitting its deadline aborts the call.

Why the token is on the client, not in a transport

Other HTTP clients in platform/ leave auth to a transport the wiring installs. Conduit cannot work that way: once the parameters are JSON, it reads the token only from __conduit__ and silently ignores an api.token query or form field, answering ERR-INVALID-SESSION. A transport would have to decode and rewrite the request body, so the token is passed to NewClient instead.

That makes *Client the counterpart of the authenticated *http.Client GitHub callers take (see platform/githubapi): service wiring builds it once from its own credentials, and extensions receive it.

What a call returns

Conduit's reply Call returns
HTTP 200, result set nil, with result decoded into the caller's value
HTTP 200, result is null or [] nil, with the caller's value untouched. PHP encodes an empty map as [], so an empty array means "nothing", not "wrong shape".
HTTP 200, error_code set an *Error carrying Code and Info
any other HTTP status a platform/http.StatusError carrying the status and body
a body that is not JSON, or a result that does not fit the caller's type a plain error

Every error is wrapped with the method name.

Classifying failures
  • A StatusError is classified by platform/errs/http like any other HTTP failure: a 5xx or 429 is retryable, other statuses are not.
  • An *Error is not an HTTP status, because Conduit reports its own failures with HTTP 200. That includes a missing or rejected token (ERR-INVALID-SESSION). With no classifier for it, such an error is non-retryable infra by default, so a bad token dead-letters rather than retrying forever. A caller that knows a code means something else, such as "not applicable", matches on Code itself.

What is deliberately not here

  • Per-method wrappers. Each caller keeps its own typed request and result for the methods it calls, and decides what a missing object means for it. A method only one caller uses never lands in this package.
  • Retries, logging and metrics. Retry decisions belong to the consumer's error classifiers, and callers already log and record metrics in their own scope.

Who uses it

  • submitqueue/extension/changeprovider/phabricator reads diffs with differential.querydiffs; the orchestrator's wiring builds its client from the configured endpoint and token.

Documentation

Overview

Package conduit calls Phabricator's Conduit API: it encodes a method's parameters, authenticates the call and decodes Conduit's result envelope.

It holds one generic Call and no per-method wrappers. Each caller keeps its own typed requests and results and decides what a missing object means for it, so a method only one caller uses never lands here.

The API token travels inside the JSON parameters, as "__conduit__.token". Conduit ignores an "api.token" field once the parameters are JSON, so auth cannot be left to a transport the way it is for other HTTP APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client calls Conduit methods with one API token. It is safe for concurrent use.

func NewClient

func NewClient(httpClient *http.Client, token string) *Client

NewClient wraps httpClient, which must resolve relative paths against the Phabricator host (e.g. via platform/http.BaseURLTransport) and carries the caller's timeout and connection limits. token authenticates every call.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params, result any) error

Call invokes method with params, which must encode as a JSON object (nil sends none), and decodes the result into result unless it is nil. A non-200 reply is a *platform/http.StatusError and a Conduit error_code is an *Error. A null result, or an empty array (PHP's encoding of an empty map), leaves result untouched.

type Error

type Error struct {
	// Code is Conduit's error_code, e.g. ERR-INVALID-SESSION.
	Code string
	// Info is Conduit's error_info, a human-readable description.
	Info string
}

Error is a failure Conduit reports in its result envelope. Conduit answers such failures, including a missing or invalid token (ERR-INVALID-SESSION), with HTTP 200, so they never surface as a platform/http.StatusError.

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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