How to write empty string validation for key in struct using Validator?

Written by
Link to Post by 

I am writing a struct validator using validator.

type Model struct { CreatedBy *string `bson:"_p_createdBy" json:"_p_createdBy" blacklist:"true" validate:"required"` } 

I want to check that _p_createdBy can be empty but cannot be other than string.

examples below can pass

{ "_p_createdBy" : "" } 


{ "_p_createdBy" : "me" } 

but example below should fail

{ "_p_createdBy" : true } 

Can someone please suggest validation for that. Thanks.

submitted by /u/knrt10
[link] [comments]

Article Tags:
· ·
Article Categories:

Leave a Reply