Documentation ¶
Index ¶
- Constants
- Variables
- func BytesAreVATID(str []byte) bool
- func StringIsVATID(str string) bool
- type ID
- func (id ID) CountryCode() country.Code
- func (id ID) IsMOSS() bool
- func (id ID) Normalized() (ID, error)
- func (id ID) NormalizedOrNull() NullableID
- func (id ID) Nullable() NullableID
- func (id ID) Number() string
- func (id *ID) Scan(value any) error
- func (id *ID) ScanString(source string, validate bool) error
- func (id ID) String() string
- func (id ID) Valid() bool
- func (id ID) ValidAndNormalized() bool
- func (id ID) Validate() error
- func (id ID) ValidateIsNormalized() error
- func (id ID) Value() (driver.Value, error)
- type IDParser
- type NullableID
- func (n NullableID) CountryCode() country.NullableCode
- func (n NullableID) Get() ID
- func (n NullableID) GetOr(defaultID ID) ID
- func (n NullableID) IsMOSS() bool
- func (n NullableID) IsNotNull() bool
- func (n NullableID) IsNull() bool
- func (n NullableID) MarshalJSON() ([]byte, error)
- func (n NullableID) Normalized() (NullableID, error)
- func (n NullableID) NormalizedNotNull() (ID, error)
- func (n NullableID) NormalizedOrNull() NullableID
- func (n NullableID) Number() string
- func (n *NullableID) Scan(value any) error
- func (n *NullableID) ScanString(source string, validate bool) error
- func (n *NullableID) Set(id ID)
- func (n *NullableID) SetNull()
- func (n NullableID) String() string
- func (n NullableID) StringOr(nullString string) string
- func (n NullableID) Valid() bool
- func (n NullableID) ValidAndNormalized() bool
- func (n NullableID) ValidAndNotNull() bool
- func (n NullableID) Validate() error
- func (n NullableID) ValidateIsNormalized() error
- func (n NullableID) ValidateIsNormalizedAndNotNull() error
- func (n NullableID) Value() (driver.Value, error)
Constants ¶
const ( // IDMinLength is the minium length of a VAT ID IDMinLength = 4 // IDMaxLength is the maximum length of a VAT ID IDMaxLength = 14 + 2 // allow 2 spaces )
const MOSSSchemaVATCountryCode = "EU"
MOSSSchemaVATCountryCode or the VAT Mini One Stop Shop (MOSS) is an optional scheme that allows you to account for VAT - normally due in multiple EU countries – in just one EU country. Check out: https://europa.eu/youreurope/business/taxation/vat/vat-digital-services-moss-scheme/index_en.htm
Variables ¶
var IDFinder idFinder
Functions ¶
func BytesAreVATID ¶
BytesAreVATID returns if a byte string is a valid VAT ID
func StringIsVATID ¶
StringIsVATID returns if a string can be parsed as VATID.
Types ¶
type ID ¶
type ID string
ID is a european VAT ID. ID implements the database/sql.Scanner and database/sql/driver.Valuer interfaces, returning errors when the ID is not valid and can't be normalized. Use NullableID to read and write SQL NULL values.
func NormalizeVATID ¶
NormalizeVATID returns str as normalized VAT ID or an error.
func (ID) CountryCode ¶
CountryCode returns the country.Code of the VAT ID, or country.Invalid if the id is not valid. For a VAT Mini One Stop Shop (MOSS) ID that begins with "EU" the EU's capital Brussels' country Belgum's code country.BE will be returned. See also ID.IsMOSS.
func (ID) IsMOSS ¶
IsMOSS returns true if the ID follows the VAT Mini One Stop Shop (MOSS) schema beginning with "EU".
func (ID) Normalized ¶
Normalized returns the id in normalized form, or an error if the VAT ID is not valid.
func (ID) NormalizedOrNull ¶
func (id ID) NormalizedOrNull() NullableID
NormalizedOrNull returns the id in normalized form or Null if the VAT ID is not valid.
func (ID) Number ¶
Number returns the number part after the country code of the VAT ID, or and empty string if the id is not valid.
func (*ID) ScanString ¶
ScanString tries to parse and assign the passed source string as value of the implementing type.
If validate is true, the source string is checked for validity before it is assigned to the type.
If validate is false and the source string can still be assigned in some non-normalized way it will be assigned without returning an error.
func (ID) String ¶
String returns the normalized ID if possible, else it will be returned unchanged as string. String implements the fmt.Stringer interface.
func (ID) ValidAndNormalized ¶
ValidAndNormalized returns if id is a valid and normalized VAT ID.
func (ID) ValidateIsNormalized ¶
ValidateIsNormalized returns an error if id is not a valid and normalized VAT ID.
type NullableID ¶
type NullableID string
NullableID is identical to ID, except that the Null value (empty string) is considered valid by the Valid() and Validate() methods.
var Null NullableID
Null is an empty string and will be treatet as SQL NULL.
func (NullableID) CountryCode ¶
func (n NullableID) CountryCode() country.NullableCode
CountryCode returns the country.NullableCode of the VAT ID, or ccountry.Null if the id is null or not valid. For a VAT Mini One Stop Shop (MOSS) ID that begins with "EU" the EU's capital Brussels' country Belgum's code country.BE will be returned. See also NullableID.IsMOSS.
func (NullableID) Get ¶
func (n NullableID) Get() ID
Get returns the non nullable ID value or panics if the NullableID is null. Note: check with IsNull before using Get!
func (NullableID) GetOr ¶
func (n NullableID) GetOr(defaultID ID) ID
GetOr returns the non nullable ID value or the passed defaultID if the NullableID is null.
func (NullableID) IsMOSS ¶
func (n NullableID) IsMOSS() bool
IsMOSS returns true if the ID follows the VAT Mini One Stop Shop (MOSS) schema beginning with "EU".
func (NullableID) IsNotNull ¶
func (n NullableID) IsNotNull() bool
IsNotNull returns true if the NullableID is not null.
func (NullableID) IsNull ¶
func (n NullableID) IsNull() bool
IsNull returns true if the NullableID is null. IsNull implements the nullable.Nullable interface.
func (NullableID) MarshalJSON ¶
func (n NullableID) MarshalJSON() ([]byte, error)
MarshalJSON implements encoding/json.Marshaler by returning the JSON null value for an empty (null) string.
func (NullableID) Normalized ¶
func (n NullableID) Normalized() (NullableID, error)
Normalized returns the id in normalized form, or an error if the VAT ID is not Null and not valid.
func (NullableID) NormalizedNotNull ¶
func (n NullableID) NormalizedNotNull() (ID, error)
NormalizedNotNull returns the id in normalized form, or an error if the VAT ID is not valid or Null.
func (NullableID) NormalizedOrNull ¶
func (n NullableID) NormalizedOrNull() NullableID
NormalizedOrNull returns n in normalized form or Null if id is not valid.
func (NullableID) Number ¶
func (n NullableID) Number() string
Number returns the number part after the country code of the VAT ID, or and empty string if the id is not valid.
func (*NullableID) Scan ¶
func (n *NullableID) Scan(value any) error
Scan implements the database/sql.Scanner interface.
func (*NullableID) ScanString ¶
func (n *NullableID) ScanString(source string, validate bool) error
ScanString tries to parse and assign the passed source string as value of the implementing type.
If validate is true, the source string is checked for validity before it is assigned to the type.
If validate is false and the source string can still be assigned in some non-normalized way it will be assigned without returning an error.
func (NullableID) String ¶
func (n NullableID) String() string
String returns the normalized ID if possible, else it will be returned unchanged as string. String implements the fmt.Stringer interface.
func (NullableID) StringOr ¶
func (n NullableID) StringOr(nullString string) string
StringOr returns the NullableID as string or the passed nullString if the NullableID is null.
func (NullableID) Valid ¶
func (n NullableID) Valid() bool
Valid returns if id is a valid VAT ID or Null, ignoring normalization.
func (NullableID) ValidAndNormalized ¶
func (n NullableID) ValidAndNormalized() bool
ValidAndNormalized returns if id is Null or a valid and normalized VAT ID.
func (NullableID) ValidAndNotNull ¶
func (n NullableID) ValidAndNotNull() bool
ValidAndNotNull returns if this is a valid not Null VAIT ID.
func (NullableID) Validate ¶
func (n NullableID) Validate() error
Validate returns an error if id is not a valid VAT ID or Null, ignoring normalization.
func (NullableID) ValidateIsNormalized ¶
func (n NullableID) ValidateIsNormalized() error
ValidateIsNormalized returns an error if id is not Null or a valid and normalized VAT ID.
func (NullableID) ValidateIsNormalizedAndNotNull ¶
func (n NullableID) ValidateIsNormalizedAndNotNull() error
ValidateIsNormalizedAndNotNull returns an error if id is not a valid and normalized VAT ID.