-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Country and currency constants moved to separate packages (#19)
* Country and currency constants moved to separate packages, module version updated to v2, several minor improvements * added DecimalPlaces method for currency * Updated readme Co-authored-by: Vadim Maslov <[email protected]>
- Loading branch information
Showing
36 changed files
with
4,425 additions
and
4,510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
"scripts": { | ||
"generate": "node app.js" | ||
}, | ||
"dependencies": { | ||
"glob": "^7.1.6", | ||
"glob-promise": "^4.1.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package country | ||
|
||
import ( | ||
"database/sql/driver" | ||
"encoding/json" | ||
) | ||
|
||
// Alpha2Code represents alpha-2 code | ||
type Alpha2Code string | ||
|
||
// UnmarshalJSON unmarshall implementation for alpha2code | ||
func (code *Alpha2Code) UnmarshalJSON(data []byte) error { | ||
var str string | ||
if err := json.Unmarshal(data, &str); err != nil { | ||
return err | ||
} | ||
|
||
enumValue := Alpha2Code(str) | ||
if _, err := ByAlpha2CodeErr(enumValue); err != nil { | ||
return err | ||
} | ||
|
||
*code = enumValue | ||
return nil | ||
} | ||
|
||
// Value implementation of driver.Valuer | ||
func (code Alpha2Code) Value() (value driver.Value, err error) { | ||
if code == "" { | ||
return "", nil | ||
} | ||
|
||
var country Country | ||
|
||
if country, err = ByAlpha2CodeErr(code); err != nil { | ||
return nil, err | ||
} | ||
|
||
return country.Alpha2Code().String(), nil | ||
} | ||
|
||
// Validate implementation of ozzo-validation Validate interface | ||
func (code Alpha2Code) Validate() (err error) { | ||
_, err = ByAlpha2CodeErr(code) | ||
|
||
return | ||
} | ||
|
||
// IsSet indicates if Name is set | ||
func (code Alpha2Code) IsSet() bool { | ||
return len(string(code)) > 0 | ||
} | ||
|
||
// String implementation of Stringer interface | ||
func (code Alpha2Code) String() string { | ||
return string(code) | ||
} |
Oops, something went wrong.