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

Written by
reddit
Link to Post

https://www.reddit.com/r/golang/comments/b11t3z/how_to_write_empty_string_validation_for_key_in/ 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" : "" } 

or

{ "_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:
reddit

Leave a Reply