hi i am new on go can any one guide me how can i validate my value in struct
here is my code how can i validate width and height is present
type StructName struct {
Width uint json:"width"
Height uint json:"height"
}
hi i am new on go can any one guide me how can i validate my value in struct
here is my code how can i validate width and height is present
type StructName struct {
Width uint json:"width"
Height uint json:"height"
}
Here’s one way to do it:
type StructName struct {
Width uint `json:"width"`
Height uint `json:"height"`
}
func (s *StructName) IsHeightPresent() bool {
return s.Height != 0
}
func (s *StructName) IsWidthPresent() bool {
return s.Width != 0
}
Playground: https://play.golang.org/p/4wOSiMMTmM
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.