urlx

package
v1.34.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 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 urlx provides URL token construction and shortening utilities for embedding signed tokens in email action links

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTokenCreationFailed indicates that the token pair could not be created
	ErrTokenCreationFailed = errors.New("urlx: token creation failed")
	// ErrURLConstructionFailed indicates that the URL could not be constructed
	ErrURLConstructionFailed = errors.New("urlx: URL construction failed")
)

Functions

func BuildTokenURL

func BuildTokenURL(ctx context.Context, sl *shortlinks.Client, baseURL url.URL, token string) (string, error)

BuildTokenURL appends a token query parameter to the base URL and optionally shortens the result via the shortlinks client. If sl is nil or shortening fails, the full-length URL is returned (graceful degradation)

Types

type AnonTokenRequest

type AnonTokenRequest struct {
	// Prefix is prepended to SubjectID to form the JWT subject (e.g. "anon-tc-")
	Prefix string
	// SubjectID is the domain-specific identifier (e.g. request ID, ULID)
	SubjectID string
	// OrgID is the organization the token is scoped to
	OrgID string
	// Email is the recipient email address embedded in the token
	Email string
	// Duration is the access token lifetime
	Duration time.Duration
	// ExtraClaims is an optional callback to set domain-specific claim fields
	// (e.g. AssessmentID, TrustCenterID) on the token before signing
	ExtraClaims func(*tokens.Claims)
}

AnonTokenRequest holds the parameters for generating an anonymous JWT and embedding it in a URL

type AnonTokenResult

type AnonTokenResult struct {
	// AccessToken is the signed JWT string
	AccessToken string
	// URL is the full URL with the token embedded as a query parameter
	URL string
}

AnonTokenResult holds the generated access token and the final URL containing it

func GenerateAnonTokenURL

func GenerateAnonTokenURL(ctx context.Context, tm *tokens.TokenManager, sl *shortlinks.Client, baseURL url.URL, req AnonTokenRequest) (*AnonTokenResult, error)

GenerateAnonTokenURL creates a short-lived anonymous JWT from the request parameters, appends it to baseURL as a query parameter, and optionally shortens the result

Jump to

Keyboard shortcuts

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