api

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsClientError

func IsClientError(err error) bool

IsClientError reports whether the error is a 4xx (excluding 404/429).

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether the error is a 404 from the backend.

func IsRateLimited

func IsRateLimited(err error) bool

IsRateLimited reports whether the error is a 429.

Types

type APIError

type APIError struct {
	Status  int
	Message string
}

APIError represents a non-2xx response from the backend.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	BaseURL string
	HTTP    *http.Client
	UA      string
}

Client is a thin typed wrapper over net/http for the yank-run backend.

func New

func New(baseURL string, timeout time.Duration, version string) *Client

New builds a Client with the given base URL, timeout, and version-derived UA.

func (*Client) Create

func (c *Client) Create(req CreateReq) (*CreateResp, error)

Create posts a new snippet. Returns CreateResp with New=true on HTTP 201.

func (*Client) Get

func (c *Client) Get(id string) (*Snippet, error)

Get fetches a snippet by id.

func (*Client) Search

func (c *Client) Search(q string, limit int) ([]Hit, error)

Search runs a full-text query and returns the raw hit list.

type CreateReq

type CreateReq struct {
	Body        string   `json:"body"`
	Title       string   `json:"title,omitempty"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Author      string   `json:"author,omitempty"`
}

CreateReq is the body for POST /api/snippets.

type CreateResp

type CreateResp struct {
	ID  string `json:"id"`
	URL string `json:"url"`
	New bool   `json:"new"`
}

CreateResp is the response from POST /api/snippets. New is derived from HTTP status: 201 -> true, 200 -> false (dedup).

type Hit

type Hit struct {
	ID          string   `json:"id"`
	BodyPreview string   `json:"bodyPreview"`
	Title       string   `json:"title,omitempty"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags"`
	Author      string   `json:"author,omitempty"`
	CreatedAt   int64    `json:"createdAt"`
}

Hit is one element of the GET /api/snippets?q=... search response.

type Snippet

type Snippet struct {
	ID          string   `json:"id"`
	Body        string   `json:"body"`
	Title       string   `json:"title,omitempty"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags"`
	Author      string   `json:"author,omitempty"`
	CreatedAt   int64    `json:"createdAt"`
}

Snippet is the response from GET /api/snippets/:id.

Jump to

Keyboard shortcuts

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