taiga

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package taiga is an HTTP client for the Taiga REST API v1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToOutput

func ToOutput(err error) *output.Error

ToOutput maps client errors to the stable error envelope.

Types

type APIError

type APIError struct {
	Status       int
	Method, Path string
	Body         []byte
}

APIError is a non-2xx response from Taiga.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) IsVersionConflict

func (e *APIError) IsVersionConflict() bool

IsVersionConflict reports Taiga's optimistic-concurrency rejection: 409 or 412 (precondition failed), or 400 with a "version" key, which is what Taiga 6.7 answers in practice.

type Client

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

func New

func New(baseURL string, ts TokenSource, opts ...Option) *Client

New builds a client for baseURL (scheme://host, already normalized).

func (*Client) BaseURL

func (c *Client) BaseURL() string

func (*Client) Do

func (c *Client) Do(ctx context.Context, r Request) (*Response, error)

Do sends one API request. GET is retried up to twice on network errors and 5xx. A write whose 2xx answer cannot be read fails with *UnreadableBodyError, never with a network error.

func (*Client) GetAll

func (c *Client) GetAll(ctx context.Context, path string, q url.Values) ([]json.RawMessage, error)

GetAll returns every item of a list endpoint, asking Taiga to disable pagination and, if it paginates anyway, following the page number announced in X-Pagination-Next.

func (*Client) PrepareVersioned

func (c *Client) PrepareVersioned(ctx context.Context, path string, patch map[string]any) (map[string]any, map[string]json.RawMessage, error)

PrepareVersioned reads the resource and returns the body that would be sent (for --dry-run).

func (*Client) WriteVersioned

func (c *Client) WriteVersioned(ctx context.Context, method, path string, patch map[string]any, force bool) (*Response, error)

WriteVersioned applies patch with optimistic concurrency and one guarded retry.

func (*Client) WriteVersionedFrom added in v0.2.0

func (c *Client) WriteVersionedFrom(ctx context.Context, method, path string, patch map[string]any,
	first map[string]json.RawMessage, force bool) (*Response, error)

WriteVersionedFrom writes patch with the version of first, the snapshot the caller used to compute it. On a version conflict it re-reads once and retries only when none of the patched fields changed since first (or force is set), so a merge is never applied over newer data.

type ConflictError

type ConflictError struct {
	Method, Path string
	Fields       []string
}

ConflictError means another writer changed the fields we are updating.

func (*ConflictError) Error

func (e *ConflictError) Error() string

type NetworkError

type NetworkError struct {
	Method, Path string
	Err          error
}

NetworkError wraps transport failures.

func (*NetworkError) Error

func (e *NetworkError) Error() string

func (*NetworkError) Unwrap

func (e *NetworkError) Unwrap() error

type Option

type Option func(*Client)

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

func WithRetryWait

func WithRetryWait(d time.Duration) Option

type Request

type Request struct {
	Method string
	Path   string
	Query  url.Values
	Body   any
	Header http.Header
}

type Response

type Response struct {
	Status int
	Header http.Header
	Body   []byte
}

type StaticToken

type StaticToken Token

StaticToken is a fixed token (TAIGA_TOKEN, tests).

func (StaticToken) Token

func (s StaticToken) Token(context.Context) (Token, error)

type Token

type Token struct{ Type, Value string }

type TokenSource

type TokenSource interface {
	Token(ctx context.Context) (Token, error)
}

type UnreadableBodyError added in v0.2.0

type UnreadableBodyError struct {
	Method, Path string
	Status       int
	Header       http.Header
	Err          error
}

UnreadableBodyError is a write (POST, PATCH, PUT) that Taiga confirmed with a 2xx status whose body could not be read: the change is applied, so it must never look like a network error that is safe to repeat. The client never retries it.

func (*UnreadableBodyError) Error added in v0.2.0

func (e *UnreadableBodyError) Error() string

func (*UnreadableBodyError) Unwrap added in v0.2.0

func (e *UnreadableBodyError) Unwrap() error

Jump to

Keyboard shortcuts

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