We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Exercício: Capítulo 24, Exercício 2 (Nível: 11)
Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!
The text was updated successfully, but these errors were encountered:
https://play.golang.org/p/Re5eQ3SBg9I
package main /* - Utilizando este código: https://play.golang.org/p/9a1IAWy5E6 - ...crie uma mensagem de erro customizada utilizando fmt.Errorf(). */ import ( "encoding/json" "fmt" "log" ) type person struct { First string Last string Sayings []string } func main() { p1 := person{ First: "James", Last: "Bond", Sayings: []string{"Shaken, not stirred", "Any last wishes?", "Never say never"}, } bs, err := toJSON(p1) if err != nil { log.Println(err) } fmt.Println(string(bs)) } // toJSON needs to return an error also func toJSON(a interface{}) ([]byte, error) { errpersonalizado := fmt.Errorf("erro personalizado") bs, errpersonalizado := json.Marshal(a) return bs, errpersonalizado }
Output
{"First":"James","Last":"Bond","Sayings":["Shaken, not stirred","Any last wishes?","Never say never"]} Program exited.
Sorry, something went wrong.
Depois de assistir o video e ver como a Ellen fez, ficou assim
func toJSON(a interface{}) ([]byte, error) { //errpersonalizado := fmt.Errorf("erro personalizado") bs, err := json.Marshal(a) if err != nil { return []byte{}, fmt.Errorf("erros") } return bs, nil
Nao consegui entender o (return de bs, nil) nao poderia o retorno ser (return de bs, err)???
No branches or pull requests
Exercício: Capítulo 24, Exercício 2 (Nível: 11)
Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!
The text was updated successfully, but these errors were encountered: