Documentation
¶
Overview ¶
Package shortlinks provides a thin helper for the hosted shortlink API
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
func ContextWithoutShortlinks ¶
ContextWithoutShortlinks returns a context in which Shorten delivers the original URL
func DeterministicSlug ¶
DeterministicSlug derives a stable slug from the identifying parts of a link so a retry or a resend of the same link reuses one record instead of minting a new one each time
func DisabledFromContext ¶
DisabledFromContext reports whether shortlink creation is suppressed for this context
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 NewClientFromConfig ¶
NewClientFromConfig creates a new shortlinks client from the provided config
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"`
// LinkTTL is how long a created link stays resolvable when the caller sets no expiration
LinkTTL time.Duration `json:"linkttl" koanf:"linkttl" default:"2160h"`
}
Config holds the configuration for the shortlinks client
type CreateRequest ¶
type CreateRequest struct {
// URL is the original URL to shorten (the target URL)
URL string `json:"url"`
// Slug is an optional custom slug for the shortlink
Slug string `json:"slug,omitempty"`
// Expiration is the unix timestamp after which the link stops resolving; zero applies the
// client's LinkTTL so every link the service holds eventually expires
Expiration int64 `json:"expiration,omitempty"`
// Metadata is recorded on every click of the link
Metadata Metadata `json:"metadata,omitzero"`
}
CreateRequest describes the shortlink to create
type Metadata ¶
type Metadata struct {
// OrganizationID is the organization the link was generated for
OrganizationID string `json:"organization_id,omitempty"`
// UserID is the user the link was generated for, when the flow has one
UserID string `json:"user_id,omitempty"`
// RecipientEmail is the address the link was delivered to, when a single recipient is known
RecipientEmail string `json:"recipient_email,omitempty"`
// TrustCenterID is the trust center the link belongs to, for trust center flows
TrustCenterID string `json:"trust_center_id,omitempty"`
// Purpose names the flow that generated the link
Purpose Purpose `json:"purpose,omitempty"`
}
Metadata is the attribution the link service records on every click of a link. Core owns both ends of this contract, so new attribution is a new field here and a matching column in the service, never a free-form key
type Option ¶
type Option func(*Client)
Option is a functional option for configuring the Client
func WithEndpointURL ¶
WithEndpointURL sets a custom endpoint URL for the shortlink service
func WithLinkTTL ¶
WithLinkTTL sets the default lifetime applied to links created without an explicit expiration
type Purpose ¶
type Purpose string
Purpose names the flow that generated a link; the link service groups clicks by it
const ( // PurposeAssessmentAccess is the access link exposed on a system-owned assessment PurposeAssessmentAccess Purpose = "assessment_access" // PurposeQuestionnaireAuth is the questionnaire login link emailed to a recipient PurposeQuestionnaireAuth Purpose = "questionnaire_auth" // PurposeTrustCenterNDARequest is the NDA signing link for a trust center access request PurposeTrustCenterNDARequest Purpose = "trust_center_nda_request" // PurposeTrustCenterNDASigned is the trust center link sent once an NDA is signed PurposeTrustCenterNDASigned Purpose = "trust_center_nda_signed" // PurposeTrustCenterAuth is the time-limited trust center login link PurposeTrustCenterAuth Purpose = "trust_center_auth" )
Purposes for links that carry a signed token
const ( // PurposeWelcome is the console link in the welcome email PurposeWelcome Purpose = "welcome" // PurposeOrgInviteJoined is the console link sent once an invite is accepted PurposeOrgInviteJoined Purpose = "org_invite_joined" // PurposeTrustCenterNDAApproval is the console link sent to an NDA approver PurposeTrustCenterNDAApproval Purpose = "trust_center_nda_approval" // PurposeOrgDeletionNotice is the billing link in an organization deletion notice PurposeOrgDeletionNotice Purpose = "org_deletion_notice" // PurposeTrustCenterUpdate is the trust center link in a published-post notification PurposeTrustCenterUpdate Purpose = "trust_center_update" // PurposeSubprocessorNotification is the trust center link in a subprocessor change notification PurposeSubprocessorNotification Purpose = "subprocessor_notification" )
Purposes for tracking-only links to public or console pages that carry no credential