Help us shape the future of Go! Take the 2026 Go Developer Survey

signed

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package signed creates and verifies signed URLs: links that carry an expiry and an HMAC-SHA256 signature over their path and query, for email verification, unsubscribe links or temporary downloads.

s := signed.New(app.Key.Derive("signed.urls", 32))
link, _ := s.Sign(appURL+"/email/verify/42", time.Hour)
r.Get("/email/verify/{id}", verify).Use(s.Middleware())

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid = &errs.HTTPError{Status: http.StatusForbidden, Message: "Invalid signature."}
	ErrExpired = &errs.HTTPError{Status: http.StatusForbidden, Message: "This link has expired."}
)

Errors returned by Verify (403 for clients).

Functions

This section is empty.

Types

type Signer

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

Signer signs and verifies URLs with one key.

func New

func New(key []byte) *Signer

New returns a Signer; derive key from APP_KEY.

func (*Signer) Middleware

func (s *Signer) Middleware() func(http.Handler) http.Handler

Middleware rejects requests whose URL signature is missing, wrong or expired with 403 (and an "url.signature_invalid" security event).

func (*Signer) Sign

func (s *Signer) Sign(rawURL string, ttl time.Duration) (string, error)

Sign adds "expires" (Unix seconds; ttl 0 means no expiry) and "signature" query parameters to rawURL. Only the path and query are signed, so links keep working behind proxies and on other hosts.

func (*Signer) Verify

func (s *Signer) Verify(r *http.Request) error

Verify checks the signature (constant time) and the expiry of r's URL.

Jump to

Keyboard shortcuts

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