forked from launchdarkly/go-country-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment.go
67 lines (56 loc) · 1.74 KB
/
assignment.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
package countrycodes
import (
"fmt"
)
type Assignment int
const (
// OfficiallyAssigned
// http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
// Assigned to a country, territory, or area of geographical interest.
OfficiallyAssigned Assignment = iota
// UserAssigned
// http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#User-assigned_code_elements
// Free for assignment at the disposal of users.
UserAssigned
// ExceptionallyReserved
// http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Exceptional_reservations
// Reserved on request for restricted use
ExceptionallyReserved
// TransitionallyReserved
// http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Transitional_reservations
// Deleted from ISO 3166-1 but reserved transitionally
TransitionallyReserved
// IndeterminatelyReserved
// http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Indeterminate_reservations
// Used in coding systems associated with ISO 3166-1
IndeterminatelyReserved
// NotUsed
// http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Codes_currently_agreed_not_to_use
// Not used in ISO 3166-1 in deference to international property organization names
//
NotUsed
// Invalid
// A placeholder value
//
Invalid
)
func (a *Assignment) Valid() bool {
return *a < NotUsed
}
func NewAssignment(a string) (Assignment, error) {
switch a {
case "OfficiallyAssigned":
return OfficiallyAssigned, nil
case "UserAssigned":
return UserAssigned, nil
case "ExceptionallyReserved":
return ExceptionallyReserved, nil
case "TransitionallyReserved":
return TransitionallyReserved, nil
case "IndeterminatelyReserved":
return IndeterminatelyReserved, nil
case "NotUsed":
return NotUsed, nil
}
return Invalid, fmt.Errorf("invalid assignment")
}