api

package
v0.1.0 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

Overview

Package api provides the HTTP client for the Life@USTC API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status  int
	Method  string
	Path    string
	Message string
}

APIError represents a non-2xx response.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	Server     string
	Cred       *config.Credential
	HTTPClient *http.Client
}

Client wraps net/http with automatic auth header injection and token refresh.

func NewClient

func NewClient(server string, requireAuth bool) (*Client, error)

NewClient creates a client, optionally requiring auth.

func (*Client) Delete

func (c *Client) Delete(path string, params url.Values) (any, error)

Delete performs a DELETE request with optional query params.

func (*Client) Get

func (c *Client) Get(path string, params url.Values) (any, error)

Get performs a GET request with optional query params.

func (*Client) GetRaw

func (c *Client) GetRaw(path string, params url.Values) (*http.Response, error)

GetRaw performs a GET and returns the raw http.Response.

func (*Client) Patch

func (c *Client) Patch(path string, body any) (any, error)

Patch performs a PATCH request with a JSON body.

func (*Client) Post

func (c *Client) Post(path string, body any) (any, error)

Post performs a POST request with a JSON body.

func (*Client) PostForm

func (c *Client) PostForm(endpoint string, data url.Values) (map[string]any, error)

PostForm posts form-encoded data.

func (*Client) Put

func (c *Client) Put(path string, body any) (any, error)

Put performs a PUT request with a JSON body.

Jump to

Keyboard shortcuts

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