client

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package client provides the core client implementation for interacting with the Apicurio Registry.

The client package is the entry point for initializing and configuring the Apicurio Registry client. It abstracts the complexities of making HTTP requests to the registry and provides a clean interface for developers to use in their applications.

Features:

- Centralized configuration for base URL and authentication. - Automatic retry mechanisms for transient failures. - Thread-safe implementation suitable for concurrent use. - Extensible architecture to support additional features and middleware.

Usage:

To use the client, create a new instance using the `NewApicurioClient` function and pass a `Config` structure with the required settings such as BaseURL and AuthToken.

Example:

package main

import (
	"fmt"
	"github.com/mollie/go-apicurio-registry/client"
)

func main() {
	// Define the client configuration
	config := client.Config{
		BaseURL: "https://my-registry.example.com",
		AuthToken: "my-token",
	}

	// Initialize the client
	apiClient := client.NewApicurioClient(config)

	// Check the connection to the registry
	status, err := apiClient.CheckConnection()
	if err != nil {
		fmt.Printf("Error connecting to the registry: %v\n", err)
		return
	}
	fmt.Printf("Registry status: %v\n", status)
}

Configuration:

The `Config` struct contains the following fields: - BaseURL: The URL of the Apicurio Registry. - AuthToken: A token used for authenticating requests. - HTTPClient: (Optional) A custom HTTP client for advanced use cases.

Methods:

The client provides several methods to interact with the registry, including: - `CheckConnection`: Verifies if the registry is reachable. - `DoRequest`: Executes raw HTTP requests for advanced use cases.

Thread Safety:

The client is designed to be thread-safe and can be used in concurrent environments without additional synchronization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	AuthHeader string
}

Client is a reusable HTTP client for the SDK.

func NewClient

func NewClient(baseURL string, options ...Option) *Client

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do perform an HTTP request with optional authentication.

type Option

type Option func(*Client)

Option is a functional option for configuring the Client.

func WithAuthHeader

func WithAuthHeader(authHeader string) Option

WithAuthHeader is an option for setting an authentication header.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient is an option for setting a custom http.Client.

func WithRetryableHTTP added in v0.0.2

func WithRetryableHTTP(cfg *retryablehttp.Client) Option

WithRetryableHTTP configures the client to use hashicorp/go-retryablehttp.

Jump to

Keyboard shortcuts

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