import "code.pfad.fr/swift"
package swift provides methods to check the validity of an IBAN (and to retrieve some BIC codes).
package main import ( "fmt" "code.pfad.fr/swift" "code.pfad.fr/swift/bic" ) var germanTestIBAN = "DE75512108001245126199" func main() { iban, err := swift.ParseIBAN(germanTestIBAN) if err != nil { panic(err) } country := iban.CountryCode fmt.Println(country, country.BelongsToSEPA()) fmt.Println("BIC:", bic.FromIBAN(iban)) }
type CheckDigitsError struct { Expected int Actual int NationalCheck bool // true if the check failed at the country level (within the BBAN) }
func (e CheckDigitsError) Error() string
type CountryCode string
CountryCode is the ISO 3166-1 alpha-2 code of the country (uppercase)
func (cc CountryCode) BelongsToIBANRegistry() bool
BelongsToIBANRegistry returns true if the country is listed in the iban registry [https://www.swift.com/resource/iban-registry-pdf] as of 2023-03-22
https://www.swift.com/resource/iban-registry-pdf
func (cc CountryCode) BelongsToSEPA() bool
BelongsToSEPA indicates if a country belongs to the Single Euro Payments Area, as of 2023-03-23 [https://en.wikipedia.org/wiki/Single_Euro_Payments_Area#Coverage]
https://en.wikipedia.org/wiki/Single_Euro_Payments_Area#Coverage
type FormatError struct { Position int Expected string Got string Part string PartPosition int }
func (e FormatError) Error() string
type IBAN struct { CountryCode CountryCode CheckDigits int BBAN string }
func ParseIBAN(s string) (IBAN, error)
ParseIBAN will parse an IBAN and perform some basic checks (overall length, check digit sum). If there is a registered BBANChecker for this country code, it will be run as well. If the country code is unknown, the IBAN will be accepted.
func (iban IBAN) MaskedAndSpaced() string
MaskedAndSpaced returns the IBAN, with only the first and last 3 chars of the BBAN as well as spaces every 4 characters.
func (iban IBAN) Spaced() string
Spaced returns the IBAN with spaces between every 4 characters.
func (iban IBAN) String() string
String returns the IBAN, without spaces
type ToShortError struct { Got int Expected int }
func (e ToShortError) Error() string
https://codeberg.org/pfad.fr/swift
git clone
https://codeberg.org/pfad.fr/swift git@codeberg.org:pfad.fr/swift