Documentation
¶
Overview ¶
Package incident is the Go SDK for the incident.io public API.
The bulk of this module — every request and response type, and a method for every API endpoint — is generated from incident.io's published OpenAPI schema and lives in the client subpackage. This root package adds a small, hand-written constructor that wires up authentication and sensible defaults.
c, err := incident.New("my-api-key")
if err != nil {
return err
}
resp, err := c.IncidentsV2ListWithResponse(ctx, nil)
if err != nil {
return err
}
if resp.JSON200 == nil {
return fmt.Errorf("unexpected status %d: %s", resp.StatusCode(), resp.Body)
}
for _, inc := range resp.JSON200.Incidents {
fmt.Println(inc.Reference, inc.Name)
}
The returned *client.ClientWithResponses exposes a FooWithResponse method for every endpoint. Request and response types live in the client package.
Example ¶
Create a client and list incidents.
package main
import (
"context"
"fmt"
"log"
incident "github.com/incident-io/sdk-go"
)
func main() {
c, err := incident.New("my-api-key")
if err != nil {
log.Fatal(err)
}
resp, err := c.IncidentsV2ListWithResponse(context.Background(), nil)
if err != nil {
log.Fatal(err)
}
if resp.JSON200 == nil {
log.Fatalf("unexpected status %d: %s", resp.StatusCode(), resp.Body)
}
for _, inc := range resp.JSON200.Incidents {
fmt.Printf("%s %s\n", inc.Reference, inc.Name)
}
}
Output:
Index ¶
Examples ¶
Constants ¶
const DefaultEndpoint = "https://api.incident.io"
DefaultEndpoint is the base URL of the incident.io public API.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(apiKey string, opts ...Option) (*client.ClientWithResponses, error)
New returns a client for the incident.io public API, authenticated with the given API key.
By default the client makes a single attempt per request and does not retry. Pass WithRetries to opt in to automatic retrying of transient failures.
Types ¶
type Option ¶
type Option func(*config)
Option configures the client returned by New.
func WithEndpoint ¶
WithEndpoint overrides the API base URL. Defaults to DefaultEndpoint.
func WithHTTPClient ¶
func WithHTTPClient(doer client.HttpRequestDoer) Option
WithHTTPClient supplies a custom HTTP client (any client.HttpRequestDoer). When set, WithRetries is ignored — wire your own retrying transport into the client you pass here.
func WithRetries ¶
WithRetries enables automatic retrying of transient failures (network errors, 429s and 5xxs) with exponential backoff that honours the Retry-After header. Retrying is off by default. The optional maxRetries argument defaults to 4.
Example ¶
Enable automatic retries of transient failures (off by default).
package main
import (
"log"
incident "github.com/incident-io/sdk-go"
)
func main() {
c, err := incident.New("my-api-key", incident.WithRetries())
if err != nil {
log.Fatal(err)
}
_ = c
}
Output:
func WithUserAgent ¶
WithUserAgent overrides the User-Agent header sent with each request.