Documentation
¶
Overview ¶
Package api is the OpenArch REST client. The generated code is in package gen (run 'make generate' after a change to api/openapi.json).
Index ¶
- Variables
- func IsPath(ref string) bool
- type Blob
- type Client
- func (c *Client) Check(status int, what string) error
- func (c *Client) CreateDocument(ctx context.Context, parent string, body []byte) (Document, error)
- func (c *Client) DeleteDocument(ctx context.Context, id string) error
- func (c *Client) Download(ctx context.Context, ref string, w io.Writer) (DownloadResult, error)
- func (c *Client) GetDocument(ctx context.Context, ref string) (Document, error)
- func (c *Client) GroupExists(ctx context.Context, id string) (bool, error)
- func (c *Client) ListChildren(ctx context.Context, ref string, o ListOptions) (QueryResult, error)
- func (c *Client) Ping(ctx context.Context) (PingResult, error)
- func (c *Client) Query(ctx context.Context, o QueryOptions) (QueryResult, error)
- func (c *Client) ReplaceFile(ctx context.Context, parent, name string, title, description *string, ...) (Document, bool, error)
- func (c *Client) Transport(err error, what string) error
- func (c *Client) URL() string
- func (c *Client) UpdateDocument(ctx context.Context, ref string, body []byte) (Document, error)
- func (c *Client) UploadFile(ctx context.Context, parent, name, title, description, mimeType string, ...) (Document, error)
- type Document
- type DownloadResult
- type ListOptions
- type PingResult
- type QueryOptions
- type QueryResult
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is wrapped by the errors of calls that got HTTP 404.
Functions ¶
Types ¶
type Blob ¶ added in v0.3.1
type Blob struct {
Filename string `json:"filename"`
MimeType string `json:"mimeType"`
Length int64 `json:"length"`
Digest string `json:"digest"`
}
Blob describes the file of a SysFile document (property sysfile_blob). Digest is the SHA-256 of the content, in hex.
type Client ¶
type Client struct {
Gen *gen.ClientWithResponses
// contains filtered or unexported fields
}
Client calls the OpenArch API with one set of credentials.
func New ¶
New returns a client. log receives one debug line per request and response, with the Authorization header redacted.
func (*Client) Check ¶
Check maps an HTTP status to a CLI error. 401 and 403 are authentication errors (exit code 6); other non-2xx statuses are remote errors (exit code 5). A 403 means the user is known but has no permission, so its hint is not about the password.
func (*Client) CreateDocument ¶
CreateDocument creates a document under a parent given by id or path. body is a JSON object.
func (*Client) DeleteDocument ¶
DeleteDocument deletes a document by id.
func (*Client) Download ¶ added in v0.3.1
Download writes the file of the document ref to w and checks its SHA-256 against the digest stored by OpenArch.
func (*Client) GetDocument ¶
GetDocument returns a document by id, or by path when ref starts with "/".
func (*Client) GroupExists ¶ added in v0.6.0
GroupExists reports whether OpenArch knows a group id. OpenArch reads its groups from the users file only at startup, so a group added to the file is unknown until the next 'openarch up'.
func (*Client) ListChildren ¶ added in v0.3.1
func (c *Client) ListChildren(ctx context.Context, ref string, o ListOptions) (QueryResult, error)
ListChildren returns the documents in the folder ref, sorted by name. It reads the database (sync), so a new document shows at once.
func (*Client) Ping ¶
func (c *Client) Ping(ctx context.Context) (PingResult, error)
Ping reads the server version and checks the credentials with an authenticated call.
func (*Client) Query ¶
func (c *Client) Query(ctx context.Context, o QueryOptions) (QueryResult, error)
Query runs a query (POST /api/query).
func (*Client) ReplaceFile ¶ added in v0.5.0
func (c *Client) ReplaceFile(ctx context.Context, parent, name string, title, description *string, mimeType string, content io.Reader) (Document, bool, error)
ReplaceFile puts content into the SysFile document named name under parent. A nil title or description keeps the value of the document; a new document gets the name as its title. When there is no such document, it uploads a new one. It reports whether a document was replaced.
func (*Client) UpdateDocument ¶ added in v0.5.0
UpdateDocument changes the properties in body (a JSON object) of the document ref, given by id or path. Properties not in body keep their value.
func (*Client) UploadFile ¶ added in v0.3.1
func (c *Client) UploadFile(ctx context.Context, parent, name, title, description, mimeType string, content io.Reader) (Document, error)
UploadFile creates a SysFile document under parent and attaches content: it creates the document, uploads the content (POST /api/upload), then sets sysfile_blob to the upload. When a later step fails, the new document is deleted again. An empty description is left out.
type Document ¶
type Document struct {
Raw json.RawMessage
// contains filtered or unexported fields
}
Document is a document as returned by OpenArch. It is kept as raw JSON, so that no property is lost, with the fields the CLI shows in text mode decoded.
func (Document) MarshalJSON ¶
MarshalJSON writes the document exactly as OpenArch returned it.
type DownloadResult ¶ added in v0.3.1
DownloadResult describes a downloaded file.
type ListOptions ¶ added in v0.3.1
ListOptions are the inputs of ListChildren.
type PingResult ¶
type PingResult struct {
URL string `json:"url"`
User string `json:"user"`
Version string `json:"version,omitempty"`
Authenticated bool `json:"authenticated"`
Sources auth.Sources `json:"sources"`
Workspace string `json:"workspace,omitempty"`
}
PingResult is the outcome of Ping.
type QueryOptions ¶
type QueryOptions struct {
Query string
Syntax string // "" (hxql) or "expr"
Limit int64
Offset int64
Sort []string
// Sync waits until the full-text index has the latest changes.
Sync bool
// Total asks the server to count every match.
Total bool
}
QueryOptions are the inputs of Query.
type QueryResult ¶
type QueryResult struct {
Raw json.RawMessage
Documents []Document
Count int64
TotalCount int64
Offset int64
Truncated bool
}
QueryResult is the result of a query, kept as raw JSON with the documents decoded.
func (QueryResult) MarshalJSON ¶
func (r QueryResult) MarshalJSON() ([]byte, error)
MarshalJSON writes the result exactly as OpenArch returned it.