Skip to content
Snippets Groups Projects
Commit 9b447fdc authored by gbe's avatar gbe
Browse files

Clean up handling and loading of ISO2 country codes

parent 3638474e
No related branches found
No related tags found
No related merge requests found
......@@ -98,7 +98,7 @@ func (h Handler) detailsPost(w http.ResponseWriter, r *http.Request) {
return
}
country, err := ISO3CountryFromString(r.FormValue("country"))
country, err := ISO2CountryCodeFromString(r.FormValue("country"))
if err != nil {
httpError(w, "can't parse country", nil, http.StatusBadRequest)
return
......
......@@ -32,7 +32,7 @@ type ISO2CountryCode [2]byte
var UnknownCountry = ISO2CountryCode{'X', 'X'}
func ISO3CountryFromString(s string) (ISO2CountryCode, error) {
func ISO2CountryCodeFromString(s string) (ISO2CountryCode, error) {
if len(s) == 0 {
return UnknownCountry, nil
}
......@@ -45,6 +45,10 @@ func ISO3CountryFromString(s string) (ISO2CountryCode, error) {
}
func (i ISO2CountryCode) String() string {
if i[0] == 0 || i[1] == 0 {
return "XX"
}
return fmt.Sprintf("%c%c", i[0], i[1])
}
......@@ -59,7 +63,7 @@ func (i *ISO2CountryCode) UnmarshalBinary(d []byte) error {
return nil
}
*i = ISO2CountryCode{d[0], d[1]}
copy(i[:], d)
return nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment