Add documentation about error cases

This commit is contained in:
Gabriel Augendre 2023-03-12 01:27:20 +01:00
parent 614fd2fdd7
commit 561289614f

View file

@ -67,6 +67,7 @@ type InseeData struct {
// NewInseeData generates an InseeData struct, extracting the data into the relevant fields. // NewInseeData generates an InseeData struct, extracting the data into the relevant fields.
// The data is converted to a human-readable format before being stored. // The data is converted to a human-readable format before being stored.
// If a value can't be determined, the corresponding field is generally set to Unknown. // If a value can't be determined, the corresponding field is generally set to Unknown.
// It returns an error when the given number isn't 15 characters long.
func NewInseeData(inseeNumber string) (*InseeData, error) { func NewInseeData(inseeNumber string) (*InseeData, error) {
if len(inseeNumber) != 15 { if len(inseeNumber) != 15 {
return nil, fmt.Errorf("le numéro INSEE doit contenir 15 caractères") return nil, fmt.Errorf("le numéro INSEE doit contenir 15 caractères")
@ -147,6 +148,7 @@ func NewInseeData(inseeNumber string) (*InseeData, error) {
// IsValid returns true when the insee number is valid and false when not. // IsValid returns true when the insee number is valid and false when not.
// The insee number is valid when it matches its ControlKey. // The insee number is valid when it matches its ControlKey.
// It returns an error when the insee number can't be converted to an integer.
func (insee InseeData) IsValid() (bool, error) { func (insee InseeData) IsValid() (bool, error) {
r := strings.NewReplacer( r := strings.NewReplacer(
"2A", "19", "2A", "19",