incident package - github.com/incident-io/sdk-go - Go Packages

incident

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 7 Imported by: 0

README

incident.io Go SDK

Go Reference

The official Go SDK for the incident.io public API.

It is generated automatically from our published OpenAPI schema, so it always tracks the live API — there is a method for every endpoint, and a Go type for every request and response.

Install

go get github.com/incident-io/sdk-go

Requires Go 1.24 or later.

Quickstart

Create an API key in your incident.io dashboard under Settings → API keys, then:

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)
	}
}

Every endpoint has a ...WithResponse method that returns a typed response. Inspect resp.StatusCode() and the resp.JSONxxx fields (e.g. JSON200, JSON404) to handle results — a nil JSON200 means the API returned a non-2xx status, and resp.Body holds the raw payload.

Configuration

New takes functional options:

c, err := incident.New("my-api-key",
	incident.WithEndpoint("https://api.incident.io"), // override the base URL
	incident.WithUserAgent("my-app/1.0.0"),           // identify your integration
	incident.WithRetries(),                           // opt in to automatic retries
	incident.WithHTTPClient(myHTTPClient),            // bring your own *http.Client
)
Retries

By default the client makes a single attempt per request and does not retry. Pass WithRetries() to enable exponential backoff on transient failures (network errors, 429s and 5xxs); it honours the Retry-After header. Pass WithRetries(n) to cap the number of retries (default 4).

If you supply your own client with WithHTTPClient, WithRetries is ignored — configure retrying on the client you pass in.

Versioning

Releases are cut automatically whenever the API schema changes. We use SemVer: additive API changes bump the minor version and backwards-compatible fixes bump the patch version. Changes that would break Go consumers are never released automatically — they require a deliberate major version.

Support

Found a bug or missing something? Please open an issue. For questions about the API itself, see the API docs.

Note that client/client.gen.go is generated — please don't send PRs editing it directly; changes there come from the upstream schema.

License

MIT — see LICENSE.

This SDK's generated code is produced by oapi-codegen, which is licensed under Apache-2.0.

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)
	}
}

Index

Examples

Constants

View Source
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

func WithEndpoint(endpoint string) Option

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

func WithRetries(maxRetries ...int) Option

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
}

func WithUserAgent

func WithUserAgent(userAgent string) Option

WithUserAgent overrides the User-Agent header sent with each request.

Directories

Path Synopsis
Package client provides primitives to interact with the openapi HTTP API.
Package client provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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