confluence

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 13 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.

Documentation

Overview

Package confluence is a thin REST client for Confluence Cloud: enough of the API to fill the page mirror, plus the user-initiated page writes that go through the origin (create / update). It never writes to gadak's SQLite mirror — after a write, callers re-read from the origin (and, on a later surface, SyncPage the same way SyncIssue follows a Jira write).

The token lives only in the Authorization header. It is never put in an error, a log line or a URL (constitution article 8).

Index

Constants

This section is empty.

Variables

View Source
var ErrAuth = atlhttp.Auth("confluence")

ErrAuth is the Confluence-named rejected credential. It unwraps to atlhttp.ErrAuth so Watch detects it without a per-source branch. Error() keeps the "confluence:" prefix so last_error names the source. Callers keep using errors.Is(err, confluence.ErrAuth).

View Source
var ErrConflict = &APIError{Status: http.StatusConflict}

ErrConflict is a 409. On update, that is a stale version.number: the caller refetches and decides. This client does not retry a 409.

View Source
var ErrNotFound = errors.New("confluence: content not found")

ErrNotFound marks a 404 on a specific content id. A page can vanish (or get view-restricted) between the CQL listing and the per-page fetch on a busy site; callers skip that page instead of aborting the run.

Functions

This section is empty.

Types

type APIError added in v0.16.0

type APIError struct {
	Status int
	Body   string
}

APIError is a non-2xx Confluence answer with its HTTP status. Callers distinguish a stale version (409) from other rejections with Status or errors.Is(err, ErrConflict) — not by matching a human-readable substring. The shape follows jira.APIError.

func (*APIError) Error added in v0.16.0

func (e *APIError) Error() string

func (*APIError) Is added in v0.16.0

func (e *APIError) Is(target error) bool

Is reports whether target is an APIError with the same Status. That is how ErrConflict matches any 409, including a wrapped one.

type Attachment added in v0.22.0

type Attachment struct {
	ID         string  `json:"id"`
	Title      string  `json:"title"`
	Version    Version `json:"version"`
	Extensions struct {
		// MimeType is the browser-facing type ("image/png"); mediaType is the
		// same string under its other REST v1 name. One of them is always set
		// on a real row.
		MimeType  string      `json:"mimeType"`
		MediaType string      `json:"mediaType"`
		FileSize  json.Number `json:"fileSize"`
	} `json:"extensions"`
}

Attachment is one row of a page's child/attachment listing (GDK-1541). Title is the filename. The extensions object carries the type as a string; fileSize arrives as a string on some sites and as a JSON number on others (GDK-1900: a number killed every Confluence pass on a real Cloud site), so it decodes as json.Number, which accepts both.

func (Attachment) MIMEType added in v0.22.0

func (a Attachment) MIMEType() string

MIMEType returns the row's file type — mimeType when the row carries it, else mediaType. Empty when neither is set.

func (Attachment) Size added in v0.22.0

func (a Attachment) Size() int64

Size parses extensions.fileSize. 0 when absent or not a number: the mirror treats an unknown size as "no claim", never as an error.

type BodyADF

type BodyADF struct {
	Value          string `json:"value"`
	Representation string `json:"representation"`
}

BodyADF holds body.atlas_doc_format; Value is the ADF document as a JSON string.

type ChildAttachments added in v0.23.0

type ChildAttachments = ChildList

ChildAttachments and ChildComments are the same envelope — every children.<kind> expansion the search offers has this shape — so one struct carries both names rather than two identical copies drifting apart.

type ChildComments added in v0.23.0

type ChildComments = ChildList

ChildAttachments and ChildComments are the same envelope — every children.<kind> expansion the search offers has this shape — so one struct carries both names rather than two identical copies drifting apart.

type ChildList added in v0.23.0

type ChildList struct {
	Results []struct {
		ID string `json:"id"`
	} `json:"results"`
	Start int `json:"start"`
	Limit int `json:"limit"`
	Size  int `json:"size"`
}

ChildList is one children.* expansion: the first results page only. Size is the row count in Results (at most Limit); Size < Limit means the list is complete, Size == Limit means it may be truncated — a caller comparing ids must refuse the truncated shape (GDK-1888). Measured on a real Cloud site: default limit 25.

type Client

type Client struct {
	HTTP *http.Client
	// Retries is the total number of attempts per request; Backoff is the first
	// wait, doubling per attempt and capped at 30 s.
	Retries int
	Backoff time.Duration
	// PauseBetween is slept after each Page fetch (rate politeness). Zero in tests.
	PauseBetween time.Duration
	// PauseDecide, when set, is consulted before each PauseBetween sleep in
	// Page: returning false skips the pause. The sync pass's fetch pool sets
	// it (GDK-1673) so the politeness gap runs only while the pool's
	// effective width is 1 — with several requests already overlapping the
	// pause would only add latency on top. Nil keeps the pause always on.
	PauseDecide func() bool

	// UsageBox is the process-local instrument pair — call volume and the
	// per-kind request tally behind the sync pass's "sync: requests …"
	// line. Usage / TakeUsage / TakeRequestBreakdown promote from it. The
	// breakdown also carries the PauseBetween sleep, which no request
	// meter sees. Never blocks a request (counters are atomic).
	atlhttp.UsageBox
	// contains filtered or unexported fields
}

Client talks to Confluence Cloud under <site>/wiki.

func New

func New(site, email, token string) *Client

New builds a client. site is the Atlassian origin (no /wiki suffix).

func (*Client) AddPageComment added in v0.16.1

func (c *Client) AddPageComment(ctx context.Context, pageID, adf string) (Comment, error)

AddPageComment POSTs a top-level comment on a page (v1 content with type=comment and the page as container). ADF is the atlas_doc_format value as a JSON string, same as CreatePage.

func (*Client) Attachments added in v0.22.0

func (c *Client) Attachments(ctx context.Context, pageID string) ([]Attachment, error)

Attachments lists a page's file attachments — child/attachment with the same start/limit paging childComments uses. The rows carry metadata only; the bytes come from content/{id}/download, which is the proxy's route, not a stored URL (GDK-1541).

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL is the wiki origin (…/wiki), used to build deep links.

func (*Client) Comments

func (c *Client) Comments(ctx context.Context, pageID string) ([]Comment, error)

Comments returns every comment on a page plus one level of replies (start/limit paging on each parent), tagging each row with its thread parent: ParentID empty on a top-level comment, the parent's id on a reply (GDK-1888).

func (*Client) CreatePage added in v0.16.0

func (c *Client) CreatePage(ctx context.Context, spaceKey, title, adf string, parentID string) (Page, error)

CreatePage POSTs a page to the origin. ADF is the atlas_doc_format value as a JSON string (the same representation the read path already handles). parentID, when non-empty, is sent as ancestors[0].id.

The returned page is a GET of the new id, not the request body and not the POST envelope — the origin is the record.

func (*Client) Page

func (c *Client) Page(ctx context.Context, id string) (Page, error)

Page fetches one content id with ADF body, version, space, ancestors, and labels. metadata.labels is the first page only (≤25 results); see LabelNames.

func (*Client) PageVersions added in v0.16.0

func (c *Client) PageVersions(ctx context.Context, id string) ([]Version, error)

PageVersions lists every history stamp for a content id (GET /content/{id}/version). Bodies are not requested. Pagination follows _links.next the same way SearchPages does. The server's order is not trusted: results are sorted by Number ascending before return.

func (*Client) Raw

func (c *Client) Raw(ctx context.Context, method, path string, body []byte, mutating bool) (status int, out []byte, err error)

Raw sends a request and returns the HTTP status and response body without JSON decoding. Path is relative to the wiki origin (e.g. /rest/api/… or /api/v2/… — not the /wiki prefix). Absolute URLs are rejected. mutating selects the write retry policy (429/503 only).

A completed HTTP response always returns err == nil with the status and body (including non-2xx). err is reserved for transport failures and bad paths.

func (*Client) RawWithHeaders added in v0.22.0

func (c *Client) RawWithHeaders(ctx context.Context, method, path string, body []byte, mutating bool) (status int, hdr http.Header, out []byte, err error)

RawWithHeaders is Raw that also returns the response headers — the surface `gadak api --headers` reads on wiki routes. Same retry and error contract as Raw.

func (*Client) SearchPages

func (c *Client) SearchPages(ctx context.Context, cql string, fn func([]Page) error) error

SearchPages runs a CQL search with expand=version,space and follows _links.next. fn is called once per page of results (may be empty only on the final empty page).

func (*Client) SearchPagesExpand added in v0.23.0

func (c *Client) SearchPagesExpand(ctx context.Context, cql, expand string, fn func([]Page) error) error

SearchPagesExpand is SearchPages with a caller-chosen expand list. The one caller that needs more than the default is the sync pass's reconcile scan, which adds children.attachment and children.comment (GDK-1888): an attachment or comment added or deleted does not bump the page's version, so the hourly scan compares the listed ids against the mirror and refetches the body on a difference — the incremental and full passes keep the default and carry no extra payload. expand is an in-repo constant token list, not user input, so it rides the query unescaped exactly the way the default always has.

func (*Client) SiteURL

func (c *Client) SiteURL() string

SiteURL is the Atlassian origin without /wiki.

func (*Client) Space

func (c *Client) Space(ctx context.Context, key string) (Space, error)

Space fetches one space by key with expand=homepage. 404 wraps ErrNotFound (same as Page); callers that tolerate a missing/restricted space skip it.

func (*Client) SpacePageCount added in v0.22.0

func (c *Client) SpacePageCount(ctx context.Context, key string) (int, bool)

SpacePageCount answers how many pages one space holds, in a single CQL request (GDK-965). "How big is this space?" is the question the space picker's rows want to answer before a user commits a sync scope, and walking every page to count it would cost the very scan the picker exists to avoid. The CQL is the sync pass's own shape — space=<key> AND type=page — so the count and the scope it describes cannot disagree about what a "page" is.

The number comes from the search response's totalSize, read self-verifyingly rather than trusted: totalSize is not in the documented v1 schema on every deployment, and on some endpoints it just echoes the returned page's size (a community-documented behavior — community.developer.atlassian.com/t/54435). The request asks for limit=1, which makes the two distinguishable in one round trip: an echoed totalSize cannot exceed 1, so a totalSize above 1 is a real total; totalSize 0 or 1 is accepted only when no _links.next follows (a space with no pages or exactly one). Every other shape — field absent, echoed with more pages behind it, transport error — reports ok=false, and the caller draws its placeholder instead of a confident wrong number.

func (*Client) Spaces

func (c *Client) Spaces(ctx context.Context) ([]Space, error)

Spaces lists every space the credential can see (start/limit paging). expand=homepage fills Space.Homepage so callers can store the root page id.

func (*Client) Stream added in v0.22.0

func (c *Client) Stream(ctx context.Context, method, path string, hdr http.Header) (*http.Response, error)

Stream is Raw for bytes: the response body is handed back unread so an attachment never has to fit in memory (same contract as jira.Client.Stream, which GDK-1617 wrote for exactly this reason). The caller closes it. hdr passes Range and conditional headers through; every status, including non-2xx, comes back as a response with err == nil.

func (*Client) UpdatePage added in v0.16.0

func (c *Client) UpdatePage(ctx context.Context, id, title, adf string, nextVersion int) (Page, error)

UpdatePage PUTs a page. nextVersion must be the origin's current version.number + 1. A stale number is a 409 / ErrConflict — the caller refetches and decides; this method does not retry.

The returned page is a GET after the write, same as CreatePage.

type Comment

type Comment struct {
	ID       string      `json:"id"`
	Title    string      `json:"title"`
	Body     ContentBody `json:"body"`
	Version  Version     `json:"version"`
	ParentID string      `json:"-"`
}

Comment is a child comment (or reply) on a page. ParentID says which it is — empty for a top-level comment, the parent's id for a reply. It is not on the wire: Comments fills it from its own walk (json:"-"), the same threading the caller stores (GDK-1888).

type ContentBody

type ContentBody struct {
	AtlasDocFormat *BodyADF `json:"atlas_doc_format"`
}

ContentBody is the expand=body.atlas_doc_format payload.

func (ContentBody) ADFRaw

func (b ContentBody) ADFRaw() json.RawMessage

ADFRaw returns the atlas_doc_format value as json.RawMessage for storage/FTS. Value is a JSON string of the ADF document.

type Label

type Label struct {
	Name   string `json:"name"`
	Prefix string `json:"prefix"`
	ID     string `json:"id"`
}

Label is one entry under metadata.labels.results (Confluence REST v1).

type LabelsPage

type LabelsPage struct {
	Results []Label `json:"results"`
	Size    int     `json:"size"`
	Limit   int     `json:"limit"`
	Start   int     `json:"start"`
}

LabelsPage is the expanded metadata.labels object. expand=metadata.labels returns only the first page (default limit 25). Real wiki pages almost always have single-digit labels, so paging is intentionally not followed.

type Page

type Page struct {
	ID      string      `json:"id"`
	Type    string      `json:"type"`
	Status  string      `json:"status"`
	Title   string      `json:"title"`
	Space   SpaceRef    `json:"space"`
	Version Version     `json:"version"`
	Body    ContentBody `json:"body"`
	// Metadata is present when expand includes metadata.labels (full Page fetch).
	Metadata PageMetadata `json:"metadata"`
	// Children is present when the search's expand asked for children.* —
	// today only the sync pass's reconcile scan asks (children.attachment and
	// children.comment, GDK-1888). The zero value reads as "no expansion came
	// back".
	Children PageChildren `json:"children"`
	// Ancestors, when expanded, lists the parent chain; the last entry is the direct parent.
	Ancestors []struct {
		ID string `json:"id"`
	} `json:"ancestors"`
	Links struct {
		WebUI string `json:"webui"`
	} `json:"_links"`
}

Page is a content row (search hit or full fetch).

func (Page) LabelNames

func (p Page) LabelNames() []string

LabelNames returns label names from metadata.labels.results in API order. Always returns a non-nil empty slice when none are present. Does not sort — callers that need determinism (sync → store) sort themselves.

Limit: expand=metadata.labels only includes the first results page (≤25). Pages with more labels than that will be truncated; paging is not followed because production pages typically have single-digit labels.

type PageChildren added in v0.23.0

type PageChildren struct {
	Attachment *ChildAttachments `json:"attachment"`
	// Comment lists top-level comment ids only — replies live under their
	// parent's own child listing, which the search never expands (GDK-1888).
	Comment *ChildComments `json:"comment"`
}

PageChildren is the expand=children.* object on a search hit. Only children.attachment and children.comment are decoded today: the reconcile scan compares the listed ids against the mirror without paying a per-page listing. A member is nil when the response carried no expansion (issuetap's wiki) — absent, not "none" (GDK-1888).

type PageMetadata

type PageMetadata struct {
	Labels LabelsPage `json:"labels"`
}

PageMetadata is the expand=metadata.* payload on a content row.

type Space

type Space struct {
	Key      string `json:"key"`
	Name     string `json:"name"`
	Type     string `json:"type"`
	Homepage *struct {
		ID string `json:"id"`
	} `json:"homepage"`
}

Space is one space listing row. Homepage is present when expand=homepage was requested; its id is the content id of the space's root page (same id scheme as Page.ID / pages.parent_id).

type SpaceRef

type SpaceRef struct {
	Key  string `json:"key"`
	Name string `json:"name"`
}

SpaceRef is the embedded space on a content row.

type Usage

type Usage = atlhttp.Usage

Usage is a point-in-time snapshot of this client's outbound Confluence traffic. Counters are process-local until a caller persists them (see store.api_usage).

Requests counts every HTTP attempt, including retries: that is the unit that draws from Confluence's rate budget.

Usage, TakeUsage and TakeRequestBreakdown promote from the embedded atlhttp.UsageBox (GDK-1780): one owner for the meter reads both Atlassian-family clients share.

type User

type User struct {
	AccountID   string `json:"accountId"`
	DisplayName string `json:"displayName"`
}

User is a Confluence account reference on version.by.

type Version

type Version struct {
	Number    int    `json:"number"`
	When      string `json:"when"`
	Message   string `json:"message"`
	MinorEdit bool   `json:"minorEdit"`
	By        User   `json:"by"`
}

Version is the content version stamp. Message and MinorEdit are filled on GET /content/{id}/version rows; the expand=version object on a Page fetch typically omits them.

Jump to

Keyboard shortcuts

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