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
I imagine that we need to just check if there is data in data.Verb.Syn before accessing it, but I am not sure what the cleanest way of doing that is.
bighugh.go
type words struct { Syn []string `json:"syn"` } ... syns = append(syns, data.Verb.Syn...)
curl attempt
curl http://words.bighugelabs.com/api/2/f67148bb1412bef4c1c6b25f6947e8f6/woman/json | {"noun":{"syn":["adult female","charwoman","char","cleaning woman","cleaning lady","womanhood","fair sex","adult","class","cleaner","female","female person","grownup","social class","socio-economic class"],"ant":["man"],"usr":["girl"]}}%
code attempt
echo 'woman' | ./synonyms | panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x0 pc=0x463652] goroutine 1 [running]: thesaurus.(*BigHugh).Synonyms(0xc20808bec0, 0xc20800a440, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0) /home/ozzie/src/thesaurus/bighugh.go:36 +0x942 main.main() /home/ozzie/src/github.com/oagr/blueprints/synonyms/main.go:17 +0x2a9 goroutine 8 [runnable]: net/http.(*persistConn).readLoop(0xc20806c000) /usr/lib/go/src/net/http/transport.go:928 +0x9ce created by net/http.(*Transport).dialConn /usr/lib/go/src/net/http/transport.go:660 +0xc9f goroutine 17 [syscall, locked to thread]: runtime.goexit() /usr/lib/go/src/runtime/asm_amd64.s:2232 +0x1 goroutine 9 [select]: net/http.(*persistConn).writeLoop(0xc20806c000) /usr/lib/go/src/net/http/transport.go:945 +0x41d created by net/http.(*Transport).dialConn /usr/lib/go/src/net/http/transport.go:661 +0xcbc
The text was updated successfully, but these errors were encountered:
You're right, that little block should probably be a little more forgiving:
if data.Noun != nil { syns = append(syns, data.Noun.Syn...) } if data.Verb != nil { syns = append(syns, data.Verb.Syn...) }
Thanks.
Sorry, something went wrong.
Note, that calling append(syns, data.Verb.Syn...) is OK if Syn is an empty slice. It just won't do anything. The problem is that data.Verb is nil.
append(syns, data.Verb.Syn...)
Syn
data.Verb
nil
made field access more robust by checking for nils
4ed1219
Addresses #11
No branches or pull requests
I imagine that we need to just check if there is data in data.Verb.Syn before accessing it, but I am not sure what the cleanest way of doing that is.
bighugh.go
curl attempt
code attempt
The text was updated successfully, but these errors were encountered: