Documentation
¶
Overview ¶
Package freelo is the Go SDK for the Freelo.io project-management API.
It provides a typed HTTP client (generated from the public OpenAPI spec), pluggable authentication, automatic rate limiting, and retry with exponential backoff on transient failures.
Quick start ¶
client, err := freelo.New(
freelo.WithAuth(auth.BasicAuth{Email: email, APIKey: apiKey}),
freelo.WithUserAgent("MyApp/1.0 (contact@example.com)"),
)
if err != nil {
log.Fatal(err)
}
resp, err := client.API.GetProjectsWithResponse(ctx, nil)
for _, p := range *resp.JSON200 {
fmt.Println(*p.Id, *p.Name)
}
See the examples/ directory for runnable scenarios.
Index ¶
- Constants
- type APIError
- type Client
- type Option
- func WithAuth(p auth.Provider) Option
- func WithBaseURL(raw string) Option
- func WithHTTPClient(hc *http.Client) Option
- func WithRateLimit(interval time.Duration) Option
- func WithRequestEditor(fn RequestEditorFn) Option
- func WithRetry(attempts int, base, max time.Duration) Option
- func WithUserAgent(ua string) Option
- type RequestEditorFn
Constants ¶
const ( // Freelo publishes a 25 req/min rate limit. Spacing requests by ~2.4s // keeps us safely under it; tunable via WithRateLimit (0 disables). DefaultRateInterval = 60 * time.Second / 25 // DefaultMaxAttempts caps total tries per request (initial + retries). DefaultMaxAttempts = 3 // DefaultBackoffBase / DefaultBackoffMax bound exponential backoff. DefaultBackoffBase = 500 * time.Millisecond DefaultBackoffMax = 8 * time.Second // DefaultHTTPTimeout applies when WithHTTPClient is not used. DefaultHTTPTimeout = 30 * time.Second )
Default values applied when corresponding Option is not supplied.
const DefaultBaseURL = "https://api.freelo.io/v1"
DefaultBaseURL is the production Freelo API root.
const SDKVersion = "v0.1.0-dev"
SDKVersion is the semantic version of this SDK release. Bumped by release-please based on conventional commits (see .github/workflows/ release-please.yml). Consumers should not rely on this string for feature detection — use API capability checks instead.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError represents a non-2xx response from the Freelo API after all retries have been exhausted. Surface via errors.As to inspect status code and parsed error fields.
The transport itself does not produce APIError today (the typed client returns *http.Response and the caller decides how to interpret status). This type is exported so consumer code that wants a uniform error shape can construct one from a 4xx/5xx response. Future v0.x versions may promote it into the transport once the patterns settle.
func NewAPIError ¶
NewAPIError builds an APIError from a non-2xx *http.Response. The response body is captured up to a safety cap; pass it before the body is closed elsewhere.
type Client ¶
type Client struct {
// API is the typed, fully-generated Freelo client. All endpoints from
// spec/freelo-api.yaml are reachable through it (e.g.
// API.GetProjectsWithResponse, API.CreateCommentWithBody).
API *freeloapi.ClientWithResponses
// contains filtered or unexported fields
}
Client is the entry point to the Freelo SDK. Build one with New, then reach for typed responses via Client.API or send arbitrary requests via Client.Raw. A Client is safe for concurrent use.
Internally a Client wraps a *freeloapi.ClientWithResponses with the rate-limit + retry transport, the user-supplied auth provider, and any extra request editors. Tear-down is the http.Client's responsibility — the SDK does not own goroutines.
func New ¶
New builds a Client from Options. WithAuth and WithUserAgent are required — New returns an error if either is omitted. Other options fall back to documented defaults (see DefaultBaseURL, DefaultRateInterval, DefaultMaxAttempts, DefaultHTTPTimeout).
func (*Client) BaseURL ¶
BaseURL returns the resolved API base URL (with HTTPS enforcement and trailing-slash trim already applied). Useful for callers that build requests through Do and need to know the configured root.
func (*Client) Do ¶
Do sends a pre-built *http.Request through the SDK's transport pipeline. Use this when you need control over headers (e.g. Content-Type for a JSON body, custom Accept negotiation) — set them on req before calling Do.
The auth + User-Agent editors run after the caller's headers are already set, so they can read them but Authorization / User-Agent that the caller pre-sets will be overwritten by SDK editors. That's intentional: nobody should be hand-rolling Authorization on a Freelo SDK call.
func (*Client) Raw ¶
func (c *Client) Raw(ctx context.Context, method, path string, body io.Reader) (*http.Response, error)
Raw sends an ad-hoc HTTP request through the SDK's transport pipeline (auth + User-Agent + rate limit + retry) for endpoints not covered by the generated typed client, or when callers need the bare *http.Response.
Path may be relative (joined to the configured base URL) or absolute (passed through unchanged). Body may be nil for GET/DELETE.
Raw does not set Content-Type — if you're sending a JSON body, build the request via Do instead so you can set the header yourself.
The returned *http.Response is the caller's responsibility to close.
type Option ¶
type Option func(*config) error
Option configures a Client. Apply via New(opts...).
func WithAuth ¶
WithAuth sets the credential provider applied to every request. Required; New returns an error if WithAuth is omitted.
func WithBaseURL ¶
WithBaseURL overrides the default API root. HTTPS is required — http:// URLs are rejected to prevent credential leakage. Trailing slashes are trimmed.
func WithHTTPClient ¶
WithHTTPClient overrides the default *http.Client (Timeout: 30s). Useful for injecting custom transports, proxies, or mocks in tests.
func WithRateLimit ¶
WithRateLimit sets the minimum spacing between requests issued by this Client. Pass 0 to disable client-side rate limiting (useful when the caller manages it themselves, e.g. via a shared semaphore across multiple Clients in the same process).
Default is 2.4s, calibrated to Freelo's published 25 req/min server limit.
func WithRequestEditor ¶
func WithRequestEditor(fn RequestEditorFn) Option
WithRequestEditor appends a request editor that runs after the SDK's built-in auth + User-Agent editors. Use for adding custom headers (correlation IDs, feature flags, ...) or logging.
Editors run in registration order. Returning an error short-circuits the request before it leaves the process.
func WithRetry ¶
WithRetry configures retry behavior on transient failures (network errors, 429, 5xx). attempts counts the initial try (so attempts=1 means no retry). base and max bound the exponential backoff window.
Defaults: attempts=3, base=500ms, max=8s.
func WithUserAgent ¶
WithUserAgent sets the User-Agent header. Required; Freelo rejects requests without one. The recommended form is `<App>/<Version> (<contact>)`, e.g. "MyApp/1.0 (ops@example.com)".
type RequestEditorFn ¶
type RequestEditorFn = freeloapi.RequestEditorFn
RequestEditorFn is the same shape as freeloapi.RequestEditorFn — re-exported so consumers can write editors without importing the generated package.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth defines pluggable authentication for the Freelo SDK.
|
Package auth defines pluggable authentication for the Freelo SDK. |
|
examples
|
|
|
01_quickstart
command
Quickstart: build a Freelo client and call one endpoint.
|
Quickstart: build a Freelo client and call one endpoint. |
|
02_basic_auth
command
Basic Auth with explicit error handling.
|
Basic Auth with explicit error handling. |
|
03_list_projects
command
List all projects accessible to the authenticated user.
|
List all projects accessible to the authenticated user. |
|
04_create_task
command
Create a task in a tasklist.
|
Create a task in a tasklist. |
|
05_comment_with_files
command
Post a comment with file attachments.
|
Post a comment with file attachments. |
|
06_credentials_func
command
CredentialsFunc lets the SDK look up credentials per request.
|
CredentialsFunc lets the SDK look up credentials per request. |
|
07_custom_http_client
command
Inject a custom *http.Client — corporate proxies, mTLS, custom transports, longer/shorter timeouts.
|
Inject a custom *http.Client — corporate proxies, mTLS, custom transports, longer/shorter timeouts. |
|
08_raw_passthrough
command
Use Client.Raw to call endpoints not covered by the typed client (or when you'd rather decode the response yourself).
|
Use Client.Raw to call endpoints not covered by the typed client (or when you'd rather decode the response yourself). |
|
Package freeloapi provides primitives to interact with the Freelo HTTP API.
|
Package freeloapi provides primitives to interact with the Freelo HTTP API. |
|
Package freelotime defines a time.Time wrapper that handles Freelo's two on-the-wire timestamp formats:
|
Package freelotime defines a time.Time wrapper that handles Freelo's two on-the-wire timestamp formats: |
|
internal
|
|
|
testutil
Package testutil contains shared httptest helpers used by the SDK's own unit tests.
|
Package testutil contains shared httptest helpers used by the SDK's own unit tests. |
|
scripts
|
|
|
patchgen
command
Command patchgen rewrites the oapi-codegen output so that every `time.Time` field becomes a `freelotime.Time` field.
|
Command patchgen rewrites the oapi-codegen output so that every `time.Time` field becomes a `freelotime.Time` field. |