client

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package client provides the Nahook ingestion client for sending webhooks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the Nahook ingestion client.

func New

func New(apiKey string, opts ...Option) (*Client, error)

New creates a new Nahook ingestion client. The apiKey must start with "nhk_".

func (*Client) Close added in v0.2.1

func (c *Client) Close()

Close drains the SDK-owned *http.Transport's idle connection pool. Useful for clean test teardown, graceful shutdown, or explicit reset before recycling long-lived clients. Idempotent. No-op when a caller-owned *http.Client was supplied via WithHTTPClient — that transport's lifecycle belongs to the caller.

func (*Client) HTTPClient added in v0.2.0

func (c *Client) HTTPClient() *http.Client

HTTPClient returns the underlying *http.Client used by the SDK. Useful for introspection or attaching instrumentation. Mutating the returned client affects all subsequent SDK requests.

func (*Client) Send

func (c *Client) Send(ctx context.Context, endpointID string, opts nahook.SendOptions) (*nahook.SendResult, error)

Send sends a payload to a specific endpoint. If IdempotencyKey is not set in opts, a UUID v4 is generated automatically.

func (*Client) SendBatch

func (c *Client) SendBatch(ctx context.Context, items []nahook.SendBatchItem) (*nahook.BatchResult, error)

SendBatch sends payloads to multiple specific endpoints in a single request (max 20 items).

func (*Client) Trigger

func (c *Client) Trigger(ctx context.Context, eventType string, opts nahook.TriggerOptions) (*nahook.TriggerResult, error)

Trigger fans out a payload by event type to all subscribed endpoints.

func (*Client) TriggerBatch

func (c *Client) TriggerBatch(ctx context.Context, items []nahook.TriggerBatchItem) (*nahook.BatchResult, error)

TriggerBatch fans out payloads by event types in a single request (max 20 items).

type Option

type Option func(*options)

Option configures the Client.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL sets the API base URL.

func WithHTTPClient added in v0.2.0

func WithHTTPClient(c *http.Client) Option

WithHTTPClient supplies a caller-owned *http.Client to use for all requests. The SDK uses it verbatim and does not mutate it. The caller's HTTPClient.Timeout governs request timeouts and is what TimeoutError.TimeoutMs reports — note that Go's zero-value Timeout means "no timeout", which propagates to TimeoutMs as 0. Pair this with a *http.Transport tuned for your workload, OpenTelemetry round-trippers, mTLS, or any custom RoundTripper pipeline.

func WithRetries

func WithRetries(n int) Option

WithRetries sets the maximum number of retries for retryable errors.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the HTTP request timeout. Ignored when WithHTTPClient is also supplied — the caller-owned *http.Client's Timeout governs in that case.

Jump to

Keyboard shortcuts

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