Documentation
¶
Overview ¶
Package phone holds the platform's shared phone-number helpers: redaction for logs, and three normalisers with deliberately different contracts.
Redaction ¶
Redact masks the middle of a number for safe logging, keeping the first six digits (country code plus network prefix) and the last three, so "254711222111" becomes "254711***111". A leading "+" is preserved, and a number too short to have a maskable middle is returned unchanged.
Normalisation ¶
Three functions convert to international form, and they are not interchangeable — pick by how much you trust the input:
- Normalize is the most lenient: it trims whitespace and ensures a leading "+", nothing more. Use it when the number is already known to carry a country code (e.g. a YellowCard destination).
- E164 is the strictest: it strips separators, turns a "00" prefix into "+", and returns "" for a national-format number (leading "0", no country code) rather than guess a country. Use it where a wrong number is worse than none, such as the SEP-9 mobile_number sent to anchors.
- Format strips non-digits and prepends a country code (default +254) when the number is not already international.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func E164 ¶
E164 normalises a phone number to the "+<country><subscriber>" form. Separators are removed, a "00" international prefix becomes "+", and a bare international number gains a "+". A national-format number (leading "0", no country code) cannot be resolved without country context and yields "" so the caller omits the field rather than sending a wrong one.
func Format ¶
Format strips non-digits from a phone number and prepends a country code when the number is not already international. countryCode defaults to "+254" (Kenya) when empty.
func Normalize ¶
Normalize ensures the number is in international format with a leading "+", trimming surrounding whitespace. It neither strips separators nor validates.
Types ¶
type KenyaOperator ¶ added in v1.7.0
type KenyaOperator string
KenyaOperator names the mobile operator a Kenyan number was allocated to.
const ( OperatorUnknown KenyaOperator = "" OperatorSafaricom KenyaOperator = "safaricom" OperatorAirtel KenyaOperator = "airtel" OperatorTelkom KenyaOperator = "telkom" OperatorEquitel KenyaOperator = "equitel" )
Operators in the Communications Authority numbering plan that matter for mobile money. OperatorUnknown covers everything else, including smaller operators and numbers that are not Kenyan mobile numbers at all.
func KenyaOperatorByPrefix ¶ added in v1.7.0
func KenyaOperatorByPrefix(number string) KenyaOperator
KenyaOperatorByPrefix returns the operator a Kenyan mobile number's prefix was allocated to. It accepts +254…, 254… and 0… forms with separators.
The answer is the allocation, not the current network: numbers have been portable between operators since 2011, so a ported subscriber is reported under their old operator. Treat it as a hint and prefer the network the gateway reports for a live session.