ifc

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

README

godoc reference build status go report card total alerts license

ifc

The ifc package allows to handle Italian fiscal code.

Example

Just import the library to generate the Italian fiscal code from the data of a person.

import "github.com/whitone/ifc"

code, err := ifc.Encode("Doe", "John", 'M', "1999-12-13", "Malta")
if err != nil {
  log.Fatal(err)
}

The library also check if a code is valid and return all available informations of the person.

person, err := ifc.Decode("DOEJHN99T13Z121S")
if err != nil {
  log.Fatal(err)
}
log.Println("sex: %c, birthdate: %s, birthplace: %s", person.Sex, person.BirthDate, person.BirthPlace)

Another way to use the library is to set all required informations of person and then generate the code.

person := &ifc.Person{}
person.Surname = "Doe"
person.Name = "Jane"
person.Sex = 'F'
person.BirthDate = time.Now().AddDate(-30, 0, 0).Format("2006-01-02")
person.BirthPlace = "Palermo"
code, err := person.Ifc()
if err != nil {
  log.Fatal(err)
}

The opposite is to use the check method to fulfill the person with all its informations, be aware that any previous data will be overwritten.

person := &ifc.Person{}
err := person.CheckIfc("DOEJNA90H48G273P")
if err != nil {
  log.Fatal(err)
}
log.Println("sex: %c, birthdate: %s, birthplace: %s", person.Sex, person.BirthDate, person.BirthPlace)

Useful references

License

ifc is licensed under the BSD-3-Clause License.

Documentation

Overview

Package ifc is a library to handle Italian fiscal code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(surname string, name string, sex byte, birthDate string, birthPlace string) (code string, err error)

Encode generates an Italian fiscal code.

Types

type Person

type Person struct {
	// Surname is the last name of the person.
	Surname string
	// Name is the first name of the person.
	Name string
	// Sex can be 'M' or 'F'.
	Sex byte
	// BirthDate is the birth date in the format "YYYY-MM-DD".
	BirthDate string
	// BirthPlace is the Italian municipality or a country (in Italian language) if the birth place is outside of Italy.
	BirthPlace string
}

Person represents personal data used in Italian fiscal code.

func Decode

func Decode(code string) (p *Person, err error)

Decode checks an Italian fiscal code.

func (*Person) CheckIfc

func (p *Person) CheckIfc(code string) error

CheckIfc verifies if the code is a valid Italian fiscal code and decode it to person element.

func (*Person) Ifc

func (p *Person) Ifc() (code string, err error)

Ifc creates the Italian fiscal code of the person.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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