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

identifier

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package identifier normalizes and validates the identifiers accounts sign in with: email addresses, phone numbers and device identifiers. Every module stores and looks up identifiers in the canonical form this package produces, so one address cannot become two accounts by being spelled two ways.

Index

Constants

View Source
const (
	Email  = "email"
	Mobile = "mobile"
	Device = "device"
)

Variables

View Source
var (
	ErrInvalidEmail       = errors.New("invalid email address")
	ErrEmailDomainDenied  = errors.New("email domain is not allowed")
	ErrEmailDomainListNil = errors.New("email domain allowlist is empty")
)
View Source
var ErrInvalidMobile = errors.New("invalid phone number")

ErrInvalidMobile reports a phone number that does not parse.

Functions

func CanonicalEmail

func CanonicalEmail(email string) string

func CanonicalIdentifier

func CanonicalIdentifier(authType, identifier string) string

CanonicalIdentifier is NormalizeIdentifier for lookups: an identifier that cannot be normalized is returned as given and simply matches nothing.

func CanonicalMobile added in v1.21.0

func CanonicalMobile(number string) (string, error)

CanonicalMobile returns the E.164 form of a phone number written with its country calling code, with or without the leading "+" and with the separators people type: "86-13800138000" (the form the admin panel used to store), "+86 138 0013 8000" and "8613800138000" all give "+8613800138000". The number is parsed, not validated: an unassigned number still has one E.164 form, the one sign-in looks it up in.

func Check

func Check(areaCode, telephone string) bool

func CheckPhone

func CheckPhone(telephone string) bool

func EmailMailboxKey added in v1.21.0

func EmailMailboxKey(email string) string

EmailMailboxKey maps an email address to the mailbox that receives it: the subaddress after "+" is dropped, and Gmail ignores dots in the local part and treats googlemail.com as gmail.com. Addresses sharing a key reach one inbox, so one person could register them all. The key only detects such aliases; it is never stored or used to sign in.

func FormatToE164

func FormatToE164(area, phone string) (string, error)

FormatToE164 returns the E.164 form of a phone number given as its country calling code and national number, the form every sign-in, verification code and binding stores and looks the number up in.

func FormatToInternational

func FormatToInternational(telephone string) string

func GetCountryCode

func GetCountryCode(telephone string) string

func MaskEmail

func MaskEmail(email string) string

MaskEmail hides the local part of an email address for display, keeping only its first and last characters: alice@example.com becomes a***e@example.com. A local part of one or two characters keeps at most its first, so a short address is not given away whole, and a string that is not an address becomes "***".

func MaskPhoneNumber

func MaskPhoneNumber(phone string) string

MaskPhoneNumber parses a phone number and masks the middle of its national part, keeping the country code, the first three and the last four digits.

func NormalizeIdentifier added in v1.21.0

func NormalizeIdentifier(authType, identifier string) (string, error)

NormalizeIdentifier returns the form an identifier of authType is stored and looked up in: an email address lower-cased and trimmed, a phone number in E.164 (see CanonicalMobile). Other identifiers are opaque and returned as given. It fails for an empty email address or a phone number that does not parse.

func ValidateEmail

func ValidateEmail(email, domainList string, enforceDomain bool) (string, error)

ValidateEmail canonicalizes and validates an email address. When domain filtering is enabled, the address domain must match an allowlisted domain or one of its subdomains at a label boundary.

Types

This section is empty.

Jump to

Keyboard shortcuts

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