dln

package
v0.0.0-...-4eb781d Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 7 Imported by: 0

README

dln-go

Cuvva's library to generate, parse, and validate GB DVLA issued driving licenses.

Usage

import (
    "github.com/cuvva/dln-go"
)
Generate

From a set of user details, generate a DLN. It cannot generate the last 3 digits though as they are not based on any user details that can be provided. Additionally, you may chose to not generate the middle name character too by passing false in as a 2nd argument.

userDetails := dln.UserDetails{
    PersonalName: "Charles",
    FamilyName: "Bbaee",
    Sex: "M",
    BirthDate: "1975-07-01",
}

d, err := dln.Generate(userDetails, true)
if err != nil { /* do something */ }

// d = BBAEE707015C9
Validate

Validate a DLN against a set of user details. It will return true/false depending if the details match or not. Once more, you can chose to ignore the middle name.

d := "BBAEE707015C99WY"
userDetails := dln.UserDetails{
    PersonalName: "Charles",
    FamilyName: "Bbaee",
    Sex: "M",
    BirthDate: "1975-07-01",
}

isValid, err := dln.Validate(d, userDetails, true)
if err != nil { /* do something */ }

// isValid = true
Parse

From a DLN, attempt to parse out the user details. This is not a lossless conversion, and you will loose details. Once again, you may chose to ignore any middlenames.

d := "BBAEE707015C99WY"

userDetails, err := dln.Parse(d, true)
if err != nil { /* do something */ }

/*
userDetails := dln.UserDetails{
    PersonalName: "C",
    FamilyName: "Bbaee",
    Sex: "M",
    BirthDate: "1975-07-01",
}
*/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidInput = errors.New("invalid input")

Functions

func Generate

func Generate(userDetails UserDetails, includeMiddleName bool) (string, error)

func Validate

func Validate(dln string, userDetails UserDetails, checkMiddleName bool) (bool, error)

Types

type UserDetails

type UserDetails struct {
	PersonalName string `json:"personal_name"`
	FamilyName   string `json:"family_name"`
	Sex          string `json:"sex"`
	BirthDate    string `json:"birth_date"`
}

func Parse

func Parse(dln string, includeMiddleName bool) (*UserDetails, error)

Jump to

Keyboard shortcuts

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