-
Notifications
You must be signed in to change notification settings - Fork 63
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
Json exercise saigo #132
base: master
Are you sure you want to change the base?
Json exercise saigo #132
Conversation
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.
@kav121988 good version 1 👍
Please look at few of my comments below -
Name string `json:"name"` | ||
Age int `json:"age"` | ||
ImageUrl string `json:"imageUrl"` | ||
ID string `json:"id"` |
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.
run go fmt -w ./...
before pushing the commit. It fixes all the formatting issues.
) | ||
|
||
// Phone ... | ||
type Phone struct { | ||
Name string `json:"name"` | ||
Name string `json:"name"` |
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.
You can skip json:...
when:
- It's a single world variable (i.e. name -> Name will be automated)
- JSON key is already camel case (imageUrl - > ImageUrl)
} | ||
|
||
var allPhones []Phone | ||
|
||
func setup() { | ||
data, err := ioutil.ReadFile("phones.json") | ||
func PanicOn(err error) { |
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.
Generally, it's good idea to create functions for repeated structures. But, go error statements are exceptions.
It's pretty common to see code like -
resp, err := func1()
if err != nil {
panic(err)
}
resp2, err := func2(resp)
if err != nil {
logToSentry()
panic(err)
}
No description provided.