shortlinks

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package shortlinks provides a thin helper for the hosted shortlink API

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingAuthenticationParams indicates a missing client ID or secret
	ErrMissingAuthenticationParams = errors.New("shortlinks: missing client ID or secret")
	// ErrMissingURL indicates a missing URL
	ErrMissingURL = errors.New("shortlinks: missing URL")
	// ErrEmptyResponse indicates the API returned a nil response
	ErrEmptyResponse = errors.New("shortlinks: empty response")
	// ErrEmptyResponseBody indicates the API returned an empty body
	ErrEmptyResponseBody = errors.New("shortlinks: empty response body")
	// ErrMissingShortURL indicates the response did not contain a short URL
	ErrMissingShortURL = errors.New("shortlinks: missing short URL in response")
	// ErrClientNotConfigured indicates the shortlinks client is not configured
	ErrClientNotConfigured = errors.New("shortlinks: client not configured")
)

Functions

This section is empty.

Types

type Client added in v1.7.1

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

Client wraps the shortlink service credentials and provides methods for creating short URLs

func NewClient added in v1.7.1

func NewClient(clientID, clientSecret string, opts ...Option) (*Client, error)

NewClient creates a new shortlinks client with the provided credentials

func NewClientFromConfig added in v1.7.1

func NewClientFromConfig(cfg Config) (*Client, error)

NewClientFromConfig creates a new shortlinks client from the provided config

func (*Client) Create added in v1.7.1

func (c *Client) Create(ctx context.Context, url, slug string) (string, error)

Create issues a POST to the hosted shortlink API and returns the short URL

type Config added in v1.7.1

type Config struct {
	// Enabled indicates whether shortlinks functionality is enabled
	Enabled bool `json:"enabled" koanf:"enabled" default:"false"`
	// ClientID is the Cloudflare Access client ID for shortlink API requests
	ClientID string `json:"clientid" koanf:"clientid" default:"d5d5babbdd4ba64d59ae543ac3b6a74d.access"`
	// ClientSecret is the Cloudflare Access client secret for shortlink API requests
	ClientSecret string `json:"clientsecret" koanf:"clientsecret" default:"" sensitive:"true"`
	// EndpointURL is the shortlink service API endpoint
	EndpointURL string `json:"endpointurl" koanf:"endpointurl" default:"https://admin.s.theopenlane.io/api/links"`
}

Config holds the configuration for the shortlinks client

type Option added in v1.7.1

type Option func(*Client)

Option is a functional option for configuring the Client

func WithEndpointURL added in v1.7.1

func WithEndpointURL(url string) Option

WithEndpointURL sets a custom endpoint URL for the shortlink service

Jump to

Keyboard shortcuts

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