Skip to content

Commit

Permalink
added more search methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekonan committed Oct 29, 2020
1 parent 7b720bb commit 110b41f
Showing 1 changed file with 62 additions and 14 deletions.
76 changes: 62 additions & 14 deletions country.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ func (c Country) Value() (value driver.Value, err error) {
return c, nil
}

func (c Country) Validate(_ interface{}) error {
if _, ok := ByCountry(c); !ok {
return fmt.Errorf("'%s' is not valid ISO-3166 country name", c)
}
func (c Country) Validate(_ interface{}) (err error) {
_, err = ByCountryErr(c)

return nil
}
Expand All @@ -38,12 +36,10 @@ func (c Alpha2Code) Value() (value driver.Value, err error) {
return c, nil
}

func (c Alpha2Code) Validate(_ interface{}) error {
if _, ok := ByAlpha2Code(c); !ok {
return fmt.Errorf("'%s' is not valid ISO-3166-alpha2 code", c)
}
func (c Alpha2Code) Validate(_ interface{}) (err error) {
_, err = ByAlpha2CodeErr(c)

return nil
return
}

func (c Alpha2Code) IsSet() bool {
Expand All @@ -60,12 +56,10 @@ func (c Alpha3Code) Value() (value driver.Value, err error) {
return c, nil
}

func (c Alpha3Code) Validate(_ interface{}) error {
if _, ok := ByAlpha3Code(c); !ok {
return fmt.Errorf("'%s' is not valid ISO-3166-alpha3 code", c)
}
func (c Alpha3Code) Validate(_ interface{}) (err error) {
_, err = ByAlpha3CodeErr(c)

return nil
return
}

func (c Alpha3Code) IsSet() bool {
Expand All @@ -87,12 +81,66 @@ func ByAlpha3Code(code Alpha3Code) (result country, ok bool) {
return
}

func ByAlpha3CodeStr(code string) (result country, ok bool) {
return ByAlpha3Code(Alpha3Code(code))
}

func ByAlpha3CodeErr(code Alpha3Code) (result country, err error) {
var ok bool
result, ok = ByAlpha3Code(code)
if !ok {
err = fmt.Errorf("'%s' is not valid ISO-3166-alpha3 code", code)
}

return
}

func ByAlpha3CodeStrErr(code string) (result country, err error) {
return ByAlpha3CodeErr(Alpha3Code(code))
}

func ByAlpha2Code(code Alpha2Code) (result country, ok bool) {
result, ok = countryByAlpha2[code]
return
}

func ByAlpha2CodeStr(code string) (result country, ok bool) {
return ByAlpha2Code(Alpha2Code(code))
}

func ByAlpha2CodeErr(code Alpha2Code) (result country, err error) {
var ok bool
result, ok = ByAlpha2Code(code)
if !ok {
err = fmt.Errorf("'%s' is not valid ISO-3166-alpha2 code", code)
}

return
}

func ByAlpha2CodeStrErr(code string) (result country, err error) {
return ByAlpha2CodeErr(Alpha2Code(code))
}

func ByCountry(country Country) (result country, ok bool) {
result, ok = countryByCountry[country]
return
}

func ByCountryStr(country string) (result country, ok bool) {
return ByCountry(Country(country))
}

func ByCountryErr(country Country) (result country, err error) {
var ok bool
result, ok = ByCountry(country)
if !ok {
err = fmt.Errorf("'%s' is not valid ISO-3166 country name", country)
}

return
}

func ByCountryStrErr(country string) (result country, err error) {
return ByCountryErr(Country(country))
}

0 comments on commit 110b41f

Please sign in to comment.