api

package
v0.1.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create[T any](ctx context.Context, c *Client, path string, body any) (*T, error)

func CreateList

func CreateList[T any](ctx context.Context, c *Client, path string, body any) ([]T, error)

CreateList POSTs to an endpoint that returns a TableResponse[T] (e.g. the tag-management sub-resources on monitors, which return the full collection after the mutation rather than a single entity). Use Create when the endpoint returns SingleValueResponse[T].

func CreateRaw

func CreateRaw[T any](ctx context.Context, c *Client, path string, body any) (*T, []byte, error)

CreateRaw mirrors Create but also returns the raw response body. See GetRaw.

func Delete

func Delete(ctx context.Context, c *Client, path string) error

func DeleteWithBody

func DeleteWithBody(ctx context.Context, c *Client, path string, body any) error

DeleteWithBody issues a DELETE with a JSON request body. Used for endpoints that accept a body (e.g. DELETE /monitors/{id}/tags with a list of tag IDs).

func Get

func Get[T any](ctx context.Context, c *Client, path string) (*T, error)

func GetRaw

func GetRaw[T any](ctx context.Context, c *Client, path string) (*T, []byte, error)

GetRaw is the escape-hatch variant of Get that also returns the raw response body so callers can extract polymorphic / discriminated-union fields whose generated Go type loses information during a typed unmarshal (e.g. monitor `auth`, where the spec collapsed the oneOf into a base `MonitorAuthConfig{Type string}` and only the `type` discriminator survives). Use the typed result for everything else; only reach into the raw body for the specific field whose round-trip you need to preserve.

func IsNotFound

func IsNotFound(err error) bool

func List

func List[T any](ctx context.Context, c *Client, basePath string) ([]T, error)

func Patch

func Patch[T any](ctx context.Context, c *Client, path string, body any) (*T, error)

func PathEscape

func PathEscape(s string) string

func Update

func Update[T any](ctx context.Context, c *Client, path string, body any) (*T, error)

func UpdateRaw

func UpdateRaw[T any](ctx context.Context, c *Client, path string, body any) (*T, []byte, error)

UpdateRaw mirrors Update but also returns the raw response body. See GetRaw.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	Body       string
}

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	BaseURL     string
	Token       string
	OrgID       string
	WorkspaceID string
	HTTPClient  *http.Client
	UserAgent   string
}

func NewClient

func NewClient(baseURL, token, orgID, workspaceID, version string) *Client

type SingleValueResponse

type SingleValueResponse[T any] struct {
	Data T `json:"data"`
}

SingleValueResponse is the single-value envelope used by most endpoints.

Note on the zero-value contract: when the upstream JSON is malformed or the server returns a 2xx without a `data` field (which the API contract should never produce, but is worth being explicit about), `Data` will be the zero value of `T` and `Get`/`Create`/`Update`/`Patch` will return a non-nil pointer to that zero value. Callers should NOT treat a non-nil return as "the resource exists" — they should rely on the per-resource semantic invariants instead (e.g. `dto.Id != uuid.Nil` for newly-created resources, or `IsNotFound(err)` for explicit 404 handling). Nil-checking `&resp.Data` itself is meaningless because the address of a value-typed struct field inside a stack-allocated struct is always non-nil.

type TableResponse

type TableResponse[T any] struct {
	Data    []T  `json:"data"`
	HasNext bool `json:"hasNext"`
}

Table response wrapper used by list endpoints.

Jump to

Keyboard shortcuts

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