shortlinks

package
v2.4.13 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

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

func NewClient

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

NewClient creates a new shortlinks client with the provided credentials

func NewClientFromConfig

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

NewClientFromConfig creates a new shortlinks client from the provided config

func (*Client) Create

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

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

type Option func(*Client)

Option is a functional option for configuring the Client

func WithEndpointURL

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