api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

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

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

typed.go bridges the generated OpenAPI client with the existing auth/token-refresh logic by injecting an authTransport into the standard http.Client used by the generated code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ctx added in v0.2.0

func Ctx() context.Context

Ctx returns a background context (convenience for CLI commands).

func DecodeResponseBody added in v0.2.0

func DecodeResponseBody(body []byte, contentType string, fallbackToText bool) (any, error)

func IsJSONContentType added in v0.2.0

func IsJSONContentType(contentType string) bool

func ParseResponse added in v0.2.0

func ParseResponse[T any](resp *http.Response, err error) (any, error)

ParseResponse decodes the generated response model before adapting it for the shared table, JSON and jq presentation layer.

func ReadResponse added in v0.2.0

func ReadResponse(resp *http.Response, err error) ([]byte, string, error)

func ReadTypedResponse added in v0.2.0

func ReadTypedResponse[T any](resp *http.Response, err error) (*T, error)

ReadTypedResponse retains the generated model for callers that derive another request.

Types

type Client

type Client struct {
	Server string

	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 NewClientWithRefresh added in v0.2.0

func NewClientWithRefresh(server string, requireAuth bool, refresh refreshTokenFunc) (*Client, error)

NewClientWithRefresh creates a Client with a custom token refresh function. Pass nil for refresh to use the default auth.RefreshToken; this is intended for tests that want to inject a mock refresh without hitting the real server.

func (*Client) DoRaw added in v0.2.0

func (c *Client) DoRaw(ctx context.Context, method, path string, params url.Values, body io.Reader, contentType string, headers http.Header) (*http.Response, error)

DoRaw performs an HTTP request and returns the raw response.

type TypedClient added in v0.2.0

type TypedClient struct {
	*openapi.Client
}

TypedClient wraps the generated OpenAPI client with auth support.

func NewTypedClient added in v0.2.0

func NewTypedClient(server string, requireAuth bool) (*TypedClient, error)

NewTypedClient creates a TypedClient with auth, using the generated OpenAPI client.

Jump to

Keyboard shortcuts

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