rest

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package rest calls the JSON REST APIs the vfs adapters use (Google Drive, Docs and Sheets; Microsoft Graph) over net/http and encoding/json. It links no vendor SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(v any) []byte

Encode is v as JSON. The wire types hold only strings, finite numbers, bools and containers of them, which always encode.

Types

type Client

type Client struct {
	Base  string
	HTTP  *http.Client
	Token func() string
}

Client calls one API. Base is the API root and ends in "/"; relative paths resolve against it.

func (Client) Call

func (c Client) Call(ctx context.Context, method, path string, q url.Values, in, out any) error

Call sends in as JSON (nil: no body) and decodes the reply into out (nil: the reply is dropped). path is relative to Base, or an absolute URL under Base (a page link the API returned).

func (Client) Media

func (c Client) Media(ctx context.Context, path string, q url.Values, header http.Header) (*http.Response, error)

Media opens the reply body of a GET, with header (a Range) added. The caller closes the body.

func (Client) Stream

func (c Client) Stream(ctx context.Context, method, path string, q url.Values, contentType string, body io.Reader, out any) error

Stream sends body as is with contentType and decodes the reply into out (nil: the reply is dropped). A *bytes.Reader body sets Content-Length.

type Error

type Error struct {
	Code    int
	Message string
}

Error is a non-2xx reply: the HTTP status and the API's error message. Google and Graph both send {"error": {"message": "..."}}.

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