Repository navigation
Replies: 1 comment
|
type Coordinates struct {
Lat *float64 `json:"lat" validate:"required_with=Lng,omitempty,latitude"`
Lng *float64 `json:"lng" validate:"required_with=Lat,omitempty,longitude"`
}With
The pointers distinguish a missing coordinate from zero. Your example declares strings, which can't be nil; if you keep strings, use the same tags and treat If these fields live inside One detail in the examples: latitude Checked with validator v10.27.0, including a containing struct with an |
Uh oh!
There was an error while loading. Please reload this page.
I have a struct with 2 fields:
latitudeandlongitudeBoth of them are optional, but if 1 is present the other should be validated as required
I haven't found a combination that would work to validate these 4 cases:
I tried different variations of
required_andexcluded_andomitemptybut one of the cases always failed so farIt seems that it should be a fairly common case. Your help will be greatly appreciated!
All reactions