#How to default to nil

14 messages · Page 1 of 1 (latest)

lean flume
#

are you sending the json or receiving it? if you want to just omit them you can use a json tag and just let it be empty if its not provided

#

the empty value is already useful here

#

an empty country or number are obviously never valid

#

it's easier to work with empty strings

#

what package are you using

#

the go ecosystem in general is designed around useful zero values, so thats quite surprising. the default text/template also supports them perfectly well

#

while im not at all a fan of that package, it absolute supports that

#

The field under validation must be present and not empty only when any of the other specified fields are not present. For strings ensures value is not "". For slices, maps, pointers, interfaces, channels and functions ensures the value is not nil. For structs ensures value is not the zero value.

#

just have a validate method and write simple if statements

#

you save so much time

#

you dont have to waste time learning and reading the docs

#

the code is so easy to read and maintainble

#

and most of all, you actually understand how your validation function works