Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating unexported fields #417

Open
Jwata opened this issue Nov 14, 2018 · 12 comments
Open

Validating unexported fields #417

Jwata opened this issue Nov 14, 2018 · 12 comments
Assignees
Labels

Comments

@Jwata
Copy link

Jwata commented Nov 14, 2018

Package version eg. v8, v9:

v8 and v9

Question:

I was wondering if it's possible to validate unexported fields. But unexported fields are skipped here.
https://github.com/go-playground/validator/blob/v9/cache.go#L131

Is there any reason for it?

@deankarn
Copy link
Contributor

@Jwata A package can only view the unexported fields of types within its own package and so they must be ignored or there will be an exception; this is true of all packages using reflect even the son package.

@deankarn deankarn self-assigned this Nov 18, 2018
@Jwata
Copy link
Author

Jwata commented Nov 21, 2018

OK, so they must be exported to do validate using reflection.

@Jwata Jwata closed this as completed Nov 21, 2018
@fuintis
Copy link

fuintis commented Apr 19, 2019

As far as i know reflect can read an unexported field, but write can't. Check the following link: https://yourbasic.org/golang/access-private-field-reflection/. Also you can use reflect2 package as json-iterator/extra do: https://godoc.org/github.com/json-iterator/go/extra#SupportPrivateFields.

Is there's a way that you considirer validate unexported fields?

Many thanks un advance.

@deankarn
Copy link
Contributor

@fuintis thanks for the link, I could have sworn this was not possible but I’ll take another look! love to support unexported fields if I can

@bmassemin
Copy link

Should this issue be reopened ?
It could be handy to have a validation on unexported fields when you want your struct to be immutable.

@sz-po
Copy link

sz-po commented Jan 17, 2021

Same here. This issue completely breaks DDD entity pattern.

@gl19
Copy link

gl19 commented Mar 18, 2022

Also have the same feeling. Would love this to be looked into.

@Antonboom
Copy link

+1

@hampgoodwin
Copy link

Yeah,
This would be fantastic if it's possible 🙏

@dixonwhitmire
Copy link

Just chiming in. I ran into this issue today. I am new to Go, but happy to help develop, test, or review a proposed solution!

@Jwata Jwata reopened this Sep 14, 2022
@dixonwhitmire
Copy link

Just chiming in. I ran into this issue today. I am new to Go, but happy to help develop, test, or review a proposed solution!

Hello @Jwata and @deankarn ! I just saw that this issue is re-opened. Is there anything I can do to help?

@Jwata
Copy link
Author

Jwata commented Sep 16, 2022

I reopened this thread because other people also want this feature.

Is there anything I can do to help?

It seems @fuintis gave some ideas, which you may want to check.

nerzulk-main pushed a commit to nikolaianohyn/validator that referenced this issue Feb 22, 2024
deankarn pushed a commit that referenced this issue Mar 2, 2024
## Add supporting for validation private fields
#417


@go-playground/validator-maintainers

---------

Co-authored-by: nikolay <n.anohin@lucky.online>
d1slike pushed a commit to txix-open/validator that referenced this issue Apr 1, 2024
…ound#1234)

go-playground#417

@go-playground/validator-maintainers

---------

Co-authored-by: nikolay <n.anohin@lucky.online>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants