I have a struct that looks like this:
type DataPoint struct {
Config struct {
...
ReferenceTimestamp time.Time `json:"referenceTimestamp" binding:"required"`
} `json:"config" binding:"required"`
Measurement []struct {
...
Timestamp time.Time `json:"timestamp" binding:"required"`
} `json:"measurements" binding:"required,dive"`
}
I would like to validate that the value of the Timestamp
attribute in the Measurement
slice is before the value of the ReferenceTimestamp
in the Config
struct.
How can I achieve this with go-playground/validator (v10) + gin?
I tried to use the gtcsfield
(Config.ReferenceTimestamp) and ltcsfield
(Measurement.Timestamp) tags but it doesn’t seem to work.
I was able to make it work with a custom validator (StructLevel
), but I would like to know if there is a way to do this with the built-in tags.