Countries - ISO-639, ISO-3166 countries codes with subdivisions and names, ISO-4217 currency designators, ITU-T E.164 IDD phone codes, countries capitals, UN M.49 codes, IANA ccTLD countries domains, FIPS, IOC/NOC and FIFA codes, VERY VERY FAST, compatible with Databases/JSON/BSON/GOB/XML/CSV, Emoji countries flags and currencies, Unicode CLDR.
First of all, thank you for this amazing package! You've saved me a TON of work.
One call out I have is, this package doesn't seem to implement the database/sql/driver.Valuer and database/sql/driver.Valuer interfaces for SubdivisionCode.
How I arrived at this conclusion:
I have an API that takes in POST requests from the client, marshals it into a Go struct, then uses Gorm to store that struct model in a Postgres DB.
The struct has a field of type countries.SubdivisionCode, and the package is able to correctly unmarshal it into the struct as a string (i.e. "US-MA" --> "Massachusetts"). It also correctly inserts it into the DB as "Massachusetts." However, when I select that record from the DB and unmarshal it into a Go struct, the subdivision code field reads as "Unknown".
✅ POST request:
✅ Unmarshal the Request Body with Fiber into a Struct:
✅ Insert Into the DB:
❌ Select that Record from DB: Now the field shows up as Unknown.
On a related note, what function is causing "US-MA" to be read in as "Massachusetts" and when is that function called? Is there a way to insert it into the DB as a "US-MA"?
EDIT:
Using fmt.Printf("%+v") printed the field as "Massachusetts" (I'm guessing the package uses the String() method to do so), but when I just use fmt.Printf("%#v"), it outputs as "US-MA". Still, how is it getting inserted into the DB as "Massachusetts" when it doesn't have an explicit driver.Valuer function?
First of all, thank you for this amazing package! You've saved me a TON of work.
One call out I have is, this package doesn't seem to implement the
database/sql/driver.Valuer
anddatabase/sql/driver.Valuer
interfaces forSubdivisionCode
.How I arrived at this conclusion: I have an API that takes in POST requests from the client, marshals it into a Go struct, then uses Gorm to store that struct model in a Postgres DB. The struct has a field of type
countries.SubdivisionCode
, and the package is able to correctly unmarshal it into the struct as a string (i.e. "US-MA" --> "Massachusetts"). It also correctly inserts it into the DB as "Massachusetts." However, when I select that record from the DB and unmarshal it into a Go struct, the subdivision code field reads as "Unknown".✅ POST request:
✅ Unmarshal the Request Body with Fiber into a Struct:
✅ Insert Into the DB:
❌ Select that Record from DB: Now the field shows up as Unknown.
On a related note, what function is causing "US-MA" to be read in as "Massachusetts" and when is that function called? Is there a way to insert it into the DB as a "US-MA"?
EDIT: Using
fmt.Printf("%+v")
printed the field as"Massachusetts"
(I'm guessing the package uses the String() method to do so), but when I just usefmt.Printf("%#v")
, it outputs as"US-MA".
Still, how is it getting inserted into the DB as "Massachusetts" when it doesn't have an explicit driver.Valuer function?