Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Go JSON/v2 Package (github.com/golang)
64 points by philosopher1234 on Oct 6, 2023 | hide | past | favorite | 9 comments


Does anyone know if there is a good "config validation" package in go? I want to read in a json config file from the user, validate it with a schema that even checks for missing keys or keys that shouldn't be in the file, then if there are errors I want to print to the user the exact line of the file that is the problem. The assumption is that the user will misconfigure something and should thus be informed.


I haven’t come across anything specifically for this use case, but you could probably achieve this using either json-schema or by using struct tags from the go-playground/validator package.


validator has worked well for me, but it doesn't operate on files, rather it validates the structs after unmarshaling.

https://pkg.go.dev/github.com/go-playground/validator/v10


I am using validator now and it's okay. I did have to write some custom validators and it wasn't too well documented. Unfortunately it's a bit hard to generate the right error messages for the user to see exactly where the misconfiguration is.


Check out cue lang


How does one grok cuelang?

Asking for a friend.


This probably has the highest ratio of design doc to functional change I've ever read.


This is kinda small compared to other proposals


Supporting custom date time formats in struct tags is a huge quality of life improvement, a lot of unnecessary boilerplate saved there




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: