how to ignore a field in a struct when some data is being parsed into the struct
tags: learning go programming
content
- im seeing this code:
type userSignupForm struct {
Name string `form:"name"`
Email string `form:"email"`
Password string `form:"password"`
validator.Validator `form:"-"`
}-
the
formis next to the fields in the struct is called struct tags -
struct tags tell parsing library how to map some data to struct
- in this case, it tells Go how to map form fields to
userSignupFormstruct fields
- in this case, it tells Go how to map form fields to
-
form:"-"tells the parser to ignore this field -
this is because
validatoris just something that’s being attached touserSignupFormmodel, but it’s not a data field that’s coming from the form- it’s not meant to be populated from the form
- it’s internally used in the application’s logic