forked from tab/smartid
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathidentity.go
More file actions
54 lines (45 loc) · 1.07 KB
/
identity.go
File metadata and controls
54 lines (45 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package smartid
import (
"fmt"
"github.com/proDeveloperGuru/smartid/internal/identity"
)
// https://github.com/SK-EID/smart-id-documentation#2322-etsisemantics-identifier
const (
// TypeIDC is the identity type for identity card
TypeIDC = "IDC"
// TypePAS is the identity type for passport
TypePAS = "PAS"
// TypePNO is the identity type for personal number
TypePNO = "PNO"
)
// Identity represents semantics identifier
type Identity struct {
Country string
Type string
ID string
}
// NewIdentity creates a new identity instance
func NewIdentity(typ, country, id string) string {
i := Identity{
Country: country,
Type: typ,
ID: id,
}
return i.String()
}
// String returns a string representation
func (i *Identity) String() string {
return fmt.Sprintf("%v%v-%v", i.Type, i.Country, i.ID)
}
// Parse parses the identity number
func Parse(value string) (*Identity, error) {
result, err := identity.Parse(value)
if err != nil {
return nil, err
}
return &Identity{
Country: result.Country,
Type: result.Type,
ID: result.ID,
}, nil
}