diff --git a/address.go b/address.go index 7eb310f..7411040 100644 --- a/address.go +++ b/address.go @@ -37,18 +37,19 @@ func (a Address) IsEmpty() bool { // Format represents an address format. type Format struct { - Locale Locale `json:"locale,omitempty"` - Layout string `json:"layout,omitempty"` - LocalLayout string `json:"local_layout,omitempty"` - Required []Field `json:"required,omitempty"` - SublocalityType SublocalityType `json:"sublocality_type,omitempty"` - LocalityType LocalityType `json:"locality_type,omitempty"` - RegionType RegionType `json:"region_type,omitempty"` - PostalCodeType PostalCodeType `json:"postal_code_type,omitempty"` - PostalCodePattern string `json:"postal_code_pattern,omitempty"` - ShowRegionID bool `json:"show_region_id,omitempty"` - Regions RegionMap `json:"regions,omitempty"` - LocalRegions RegionMap `json:"local_regions,omitempty"` + Locale Locale `json:"locale,omitempty"` + Layout string `json:"layout,omitempty"` + LocalLayout string `json:"local_layout,omitempty"` + Required []Field `json:"required,omitempty"` + Defaults map[Field]string `json:"defaults,omitempty"` + SublocalityType SublocalityType `json:"sublocality_type,omitempty"` + LocalityType LocalityType `json:"locality_type,omitempty"` + RegionType RegionType `json:"region_type,omitempty"` + PostalCodeType PostalCodeType `json:"postal_code_type,omitempty"` + PostalCodePattern string `json:"postal_code_pattern,omitempty"` + ShowRegionID bool `json:"show_region_id,omitempty"` + Regions RegionMap `json:"regions,omitempty"` + LocalRegions RegionMap `json:"local_regions,omitempty"` } // IsRequired returns whether the given field is required. diff --git a/formats.go b/formats.go index a705a12..4274415 100644 --- a/formats.go +++ b/formats.go @@ -1439,8 +1439,11 @@ var formats = map[string]Format{ PostalCodePattern: `\d{3} ?\d{2}`, }, "SG": { - Layout: "%1\n%2\n%3\n%L %P", - Required: []Field{FieldLine1, FieldLocality, FieldPostalCode}, + Layout: "%1\n%2\n%3\n%L %P", + Required: []Field{FieldLine1, FieldLocality, FieldPostalCode}, + Defaults: map[Field]string{ + FieldLocality: "Singapore", + }, PostalCodePattern: `\d{6}`, }, "SH": { diff --git a/http.go b/http.go index efab169..a6d81bc 100644 --- a/http.go +++ b/http.go @@ -22,16 +22,17 @@ func (h *FormatHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { locale := h.getLocale(r) // Preselecting the layout and regions reduces HTTP request size by ~20%. type localizedFormat struct { - Locale string `json:"locale,omitempty"` - Layout string `json:"layout,omitempty"` - Required []Field `json:"required,omitempty"` - SublocalityType SublocalityType `json:"sublocality_type,omitempty"` - LocalityType LocalityType `json:"locality_type,omitempty"` - RegionType RegionType `json:"region_type,omitempty"` - PostalCodeType PostalCodeType `json:"postal_code_type,omitempty"` - PostalCodePattern string `json:"postal_code_pattern,omitempty"` - ShowRegionID bool `json:"show_region_id,omitempty"` - Regions *RegionMap `json:"regions,omitempty"` + Locale string `json:"locale,omitempty"` + Layout string `json:"layout,omitempty"` + Required []Field `json:"required,omitempty"` + Defaults map[Field]string `json:"defaults,omitempty"` + SublocalityType SublocalityType `json:"sublocality_type,omitempty"` + LocalityType LocalityType `json:"locality_type,omitempty"` + RegionType RegionType `json:"region_type,omitempty"` + PostalCodeType PostalCodeType `json:"postal_code_type,omitempty"` + PostalCodePattern string `json:"postal_code_pattern,omitempty"` + ShowRegionID bool `json:"show_region_id,omitempty"` + Regions *RegionMap `json:"regions,omitempty"` } data := make(map[string]localizedFormat, len(formats)) for countryCode, format := range formats { @@ -39,6 +40,7 @@ func (h *FormatHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { Locale: format.Locale.String(), Layout: format.SelectLayout(locale), Required: format.Required, + Defaults: format.Defaults, SublocalityType: format.SublocalityType, LocalityType: format.LocalityType, RegionType: format.RegionType,