naming

package
v0.148.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package naming applies the username rule of a normalized config.UsernameConfig: validation, derivation, renames and former names.

Index

Constants

View Source
const UsernamePattern = "^[A-Za-z][A-Za-z0-9_]*$"

UsernamePattern is the fixed character rule for interactive usernames, compatible with Go RE2 and JavaScript `u`/`v` regular expressions and HTML `pattern`. Length is governed separately.

Variables

This section is empty.

Functions

func CheckRename

func CheckRename(c config.UsernameConfig, lastRenamedAt *time.Time, now time.Time) error

CheckRename runs under the account lock. Callers authorize and detect a same-canonical-name no-op first. Trusted import updates skip it, never namespace ownership checks.

func Cooldown

func Cooldown(c config.UsernameConfig) time.Duration

Cooldown is the least time between two renames.

func Derive

func Derive(c config.UsernameConfig, s string) string

Derive turns arbitrary text into a username that satisfies Validate.

func FormerNameExpiresAt

func FormerNameExpiresAt(c config.UsernameConfig, now time.Time) *time.Time

FormerNameExpiresAt is the promise made at rename time: nil means forever, and immediate returns now (lookups and claims use the same strict now.Before(deadline)). Later policy changes never rewrite it.

func Validate

func Validate(c config.UsernameConfig, username string) error

Validate checks a trimmed username against the length rule and UsernamePattern. Length failures carry min_length/max_length metadata.

func ValidateImport

func ValidateImport(c config.UsernameConfig, username string) error

ValidateImport checks a host-provisioned username: the configured minimum, a maximum of at least 64, and hyphens are also allowed.

func WithSuffix

func WithSuffix(c config.UsernameConfig, base, suffix string) string

WithSuffix appends suffix to a derived username, trimming base (and, under a very small maximum, suffix) so the result still satisfies Validate.

Types

type Alias

type Alias struct {
	Name      string     `json:"name"`
	ExpiresAt *time.Time `json:"expires_at"`
}

Alias is a former username that still resolves to its owner.

type PolicyInfo

type PolicyInfo struct {
	Enabled                    bool                   `json:"enabled"`
	FormerNameRetentionMode    config.FormerNamesMode `json:"former_name_retention_mode"`
	FormerNameRetentionSeconds int64                  `json:"former_name_retention_seconds"`
}

PolicyInfo is the rename policy account UIs show. Timing is reported by State.NextRenameAt and RetryAfterSeconds.

type State

type State struct {
	Aliases           []Alias    `json:"aliases"`
	Policy            PolicyInfo `json:"policy"`
	Allowed           bool       `json:"allowed"`
	NextRenameAt      *time.Time `json:"next_rename_at"`
	RetryAfterSeconds int64      `json:"retry_after_seconds"`
}

State is an account's rename state.

func NewState

func NewState(c config.UsernameConfig, last *time.Time, now time.Time) State

NewState is the rename state of an account last renamed at last.

Jump to

Keyboard shortcuts

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