add jsonpath and refactor status parsing to use it #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We want a way to more flexibly parse our status JSON and hand-off responsibility for portions of the JSON we don't/won't need to support. This is in contrast to supporting the entire declarative management status updates — we'd like a way to delegate just the responsible parties access to the status that they need.
To that end we introduce
jsonpath
: a Go package for parsing JSON structures and "handling" dot/period-separated paths. If you're familiar withhttp.ServeMux
you'll see the similarities. For example in this JSON:We can "handle" a path by just specifying ".foo.bar.baz" and your handler will be called once it reaches that place in the JSON structure. For example if you setup your handlers like this:
myHandler
would be called back with a fastjson reference and a path string to handle that part of the JSON. You can even nestPathMux
ers (though you need to take care about how paths are handled and if you want to handle them in a relative fashion).In this PR we introduce this the
jsonpath
package and we refactor the status report parsing in theddm
package to use it. We also log the "unhandled" portions of the JSON to make sure we catch these if we meant to log them. For example: