instatus

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API is a client for the Instatus API.

The Instatus API is used to send status updates to the Instatus service. The service provides a simple REST API that accepts a POST request with a JSON payload to update the status of a service.

Fields:

client: The HTTP client used to make requests to the Instatus API.

func NewAPI

func NewAPI(ops ...Option) *API

NewAPI creates a new Instatus API client.

It takes a variable number of Option functions as parameters and returns a pointer to an Api struct. The Option functions are used to customize the Api struct before it is returned. If no options are provided, a new Api struct is created with default settings.

Option: An option function that takes a pointer to an Api struct and modifies it. This allows for customization of the Api struct before it is returned. Multiple options can be passed to NewAPI to configure the Api struct.

Example:

api := instatus.NewAPI(
	instatus.WithClient(&http.Client{Timeout: 5 * time.Second}),
)

// Create a new Api struct with default settings for the http.Client.
api := &instatus.Api{
	client: &http.Client{},
}

// Apply all provided options to the Api struct.
for _, op := range ops {
	op(api)
}

return api

Parameters:

ops: A variadic number of Option functions.

Returns:

A pointer to an Api struct.

func (*API) Send

func (s *API) Send(ctx context.Context, url string, status entities.Status) error

Send sends a POST request to the given URL with the specified status.

The request is sent with the provided context and the status is used to determine the value of the "trigger" field in the request payload. The request payload is a JSON object with a single key "trigger" and a value that corresponds to the status. The context is used to cancel the request if it takes too long to complete.

Returns an error if the request cannot be created, sent, or if the response cannot be read.

Parameters: - ctx: The context.Context to use for the request. - url: The URL to send the request to. - status: The entities.Status to use in the request payload.

type Option

type Option func(*API)

Option is a function that can be used to configure an Api instance.

It takes a pointer to an Api instance and returns nothing.

func WithClient

func WithClient(c http.Client) Option

WithClient returns an Option function that sets the http.Client used to send HTTP requests to the Instatus API.

The provided http.Client is used to send HTTP requests to the Instatus API. If the http.Client is nil, a new http.Client with default settings is created.

Example:

api := instatus.NewApi(
	instatus.WithClient(&http.Client{Timeout: 5 * time.Second}),
)

Returns an Option function that sets the http.Client used to send HTTP requests to the Instatus API.

Jump to

Keyboard shortcuts

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