From 9fbae0471f5bb16b60fd2a1bbb16c3c503559715 Mon Sep 17 00:00:00 2001 From: lash Date: Tue, 21 Jan 2025 15:59:44 +0000 Subject: [PATCH] Gofmt --- identity/address.go | 1 + identity/identity.go | 4 ++-- person/age.go | 3 +-- phone/phone.go | 9 +++++---- pin/pin.go | 1 - 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/identity/address.go b/identity/address.go index 4e1a2bf..b8ae45e 100644 --- a/identity/address.go +++ b/identity/address.go @@ -3,6 +3,7 @@ package identity import ( "regexp" ) + // Define the regex patterns as constants const ( addressRegex = `^0x[a-fA-F0-9]{40}$` diff --git a/identity/identity.go b/identity/identity.go index 87c7702..736d547 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -9,9 +9,9 @@ import ( // Identity contains all flavors of identifiers used across stream, api and // client for a single agent. type Identity struct { - NormalAddress string + NormalAddress string ChecksumAddress string - SessionId string + SessionId string } // CheckRecipient validates the recipient format based on the criteria diff --git a/person/age.go b/person/age.go index c6ccda2..91cab13 100644 --- a/person/age.go +++ b/person/age.go @@ -39,8 +39,7 @@ func CalculateAgeWithYOB(yob int) int { return currentYear - yob } - -//IsValidYob checks if the provided yob can be considered valid +// IsValidYob checks if the provided yob can be considered valid func IsValidYOb(yob string) bool { currentYear := time.Now().Year() yearOfBirth, err := strconv.ParseInt(yob, 10, 64) diff --git a/phone/phone.go b/phone/phone.go index 70d7b55..3f18ad5 100644 --- a/phone/phone.go +++ b/phone/phone.go @@ -8,7 +8,8 @@ import ( // Define the regex patterns as constants const ( - phoneRegex = `^(?:\+254|254|0)?((?:7[0-9]{8})|(?:1[01][0-9]{7}))$` + // TODO: This should rather use a phone package to determine whether valid phone number for any region. + phoneRegex = `^(?:\+254|254|0)?((?:7[0-9]{8})|(?:1[01][0-9]{7}))$` ) // IsValidPhoneNumber checks if the given number is a valid phone number @@ -20,7 +21,7 @@ func IsValidPhoneNumber(phonenumber string) bool { // FormatPhoneNumber formats a Kenyan phone number to "+254xxxxxxxx". func FormatPhoneNumber(phone string) (string, error) { if !IsValidPhoneNumber(phone) { - return "", errors.New("invalid phone number") + return "", errors.New("invalid phone number") } // Remove any leading "+" and spaces @@ -29,11 +30,11 @@ func FormatPhoneNumber(phone string) (string, error) { // Replace leading "0" with "254" if present if strings.HasPrefix(phone, "0") { - phone = "254" + phone[1:] + phone = "254" + phone[1:] } // Add "+" if not already present if !strings.HasPrefix(phone, "254") { - return "", errors.New("unexpected format") + return "", errors.New("unexpected format") } return "+" + phone, nil diff --git a/pin/pin.go b/pin/pin.go index 2b58647..db2d87d 100644 --- a/pin/pin.go +++ b/pin/pin.go @@ -12,7 +12,6 @@ const ( //Allowed incorrect PIN attempts AllowedPINAttempts = uint8(3) - ) // checks whether the given input is a 4 digit number