Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package client talks to the PMOCK open API.

Every request is signed with the team AK/SK; responses use the unified envelope {traceId, code, msg, data, status}. Business failures are returned as *APIError so the command layer can render the envelope and choose an exit code without string matching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildURL

func BuildURL(baseURL, path string, query url.Values) string

BuildURL joins the configured base with a spec path. It accepts either https://host/api (spec paths kept) or the documented https://host/api/open/api (prefix stripped from the path).

func IsAuthError

func IsAuthError(err error) bool

IsAuthError reports whether a business code means bad/disabled credentials.

Types

type APIError

type APIError struct {
	Code    int
	Msg     string
	TraceID string
}

APIError is a non-zero business code returned by the API.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	BaseURL    string
	AccessKey  string
	SecretKey  string
	HTTP       *http.Client
	UserAgent  string
	MaxRetries int
	// RetryNonIdempotent also retries POSTs on 5xx/network errors. Off by
	// default because create/delete must not be duplicated.
	RetryNonIdempotent bool
}

Client is safe for concurrent use.

func New

func New(baseURL, accessKey, secretKey string, timeout time.Duration) *Client

New builds a client with sane defaults.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req Request) (*Envelope, error)

Do executes a request and returns the parsed envelope. A non-zero business code is returned as *APIError together with the envelope, so callers can still print it.

type Envelope

type Envelope struct {
	TraceID string          `json:"traceId"`
	Code    int             `json:"code"`
	Msg     string          `json:"msg"`
	Data    json.RawMessage `json:"data"`
	Status  string          `json:"status"`
}

Envelope is the unified PMOCK API response.

func (*Envelope) OK

func (e *Envelope) OK() bool

OK reports whether the business code indicates success.

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
}

HTTPError is a transport-level failure that did not carry a usable envelope.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Request

type Request struct {
	Method string
	Path   string // spec path, starting with /open/api/
	Query  url.Values
	Body   any
}

Request describes one API call.

Jump to

Keyboard shortcuts

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