Answer the question
In order to leave comments, you need to log in
How to get rid of error handling curve in GO?
Essence - we open the file, there is json, we decode it.
A few lines on go:
file, err := os.Open("config.json")
ifError(err)
decoder := json.NewDecoder(file)
config := Config{}
err := decoder.Decode(&config)
ifError(err)
Answer the question
In order to leave comments, you need to log in
There is no other way to handle errors in Go. You just need to write the code correctly.
config := Config{}
data, _ := ioutil.ReadFile("config.json")
err := json.Unmarshal(data, &config)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question