-
Notifications
You must be signed in to change notification settings - Fork 38
/
record.go
75 lines (55 loc) · 1.86 KB
/
record.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
68
69
70
71
72
73
74
75
package locode
import (
"errors"
"strings"
)
// LOCODE represents code from UN/LOCODE coding scheme.
type LOCODE [2]string
// Record represents a single record of the UN/LOCODE table.
type Record struct {
// Change Indicator.
Ch string
// Combination of a 2-character country code and a 3-character location code.
LOCODE LOCODE
// Name of the locations which has been allocated a UN/LOCODE.
Name string
// Names of the locations which have been allocated a UN/LOCODE without diacritic signs.
NameWoDiacritics string
// ISO 1-3 character alphabetic and/or numeric code for the administrative division of the country concerned.
SubDiv string
// 8-digit function classifier code for the location.
Function string
// Status of the entry by a 2-character code.
Status string
// Last date when the location was updated/entered.
Date string
// The IATA code for the location if different from location code in column LOCODE.
IATA string
// Geographical coordinates (latitude/longitude) of the location, if there is any.
Coordinates string
// Some general remarks regarding the UN/LOCODE in question.
Remarks string
}
// ErrInvalidString is the error of incorrect string format of the LOCODE.
var ErrInvalidString = errors.New("invalid string format in UN/Locode")
// FromString parses string and returns LOCODE.
//
// If string has incorrect format, ErrInvalidString returns.
func FromString(s string) (*LOCODE, error) {
const locationSeparator = " "
words := strings.Split(s, locationSeparator)
if ln := len(words); ln != 1 && ln != 2 {
return nil, ErrInvalidString
}
l := new(LOCODE)
copy(l[:], words)
return l, nil
}
// CountryCode returns a string representation of country code.
func (l *LOCODE) CountryCode() string {
return l[0]
}
// LocationCode returns a string representation of location code.
func (l *LOCODE) LocationCode() string {
return l[1]
}