Skip to content

Is it possible to error when a required field is missing after unmarshalling? #930

Closed Answered by pelletier
rdbo asked this question in Questions
Discussion options

You must be logged in to vote

Really sorry I missed this question!

There is no notion of required field in go-toml. In the spirit of keeping go-toml minimal, I think this feature is better implemented outside the library, for example: https://github.com/go-playground/validator. If you want to answer the question "is this value present in the toml document?" you have three options that come to mind:

  • Unmarshal into a struct, and use a package like validator to check its result.
  • Unmarshal into an interface{} and walk its value to see what was in the file.
  • Use the unstable/parser API to iterate over each key of the document.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by rdbo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants