Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kav121988
Copy link

No description provided.

Copy link

@mokpro mokpro left a 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"`
Copy link

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"`
Copy link

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) {
Copy link

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants