-
Notifications
You must be signed in to change notification settings - Fork 30
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
add support for root-node #10
base: master
Are you sure you want to change the base?
Conversation
In some cases I can get json with multiple schemas for example REST definition GET/POST/DELETE etc. This change will try to find node in json and use it as schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
This will only look at top-level nodes, so that should probably be clarified somewhere. Probably the command line flag description or README. Or both. Either way, please update the README.
log.Fatalln("Error parsing JSON:", err) | ||
} | ||
node, ok := sub[*rootNodeName] | ||
if ok == false { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be !ok
.
if err = json.Unmarshal(file, &s); err != nil { | ||
log.Fatalln("Error parsing JSON:", err) | ||
if *rootNodeName != "" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this empty line.
} | ||
node, ok := sub[*rootNodeName] | ||
if ok == false { | ||
log.Fatalln(fmt.Sprintf("Error JSON node '%s' does not exists:", *rootNodeName), err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of combining log.Fatalln
and fmt.Sprintf
, use log.Fatalf
. Don't forget to add \n
at the end of the format string.
if ok == false { | ||
log.Fatalln(fmt.Sprintf("Error JSON node '%s' does not exists:", *rootNodeName), err) | ||
} | ||
//log.Panicf("Error reading file %v:", node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented-out code.
In some cases I can get json with multiple schemas for example REST definition GET/POST/DELETE etc.
This change will try to find node in json and use it as schema.