google-app-engine


Resolving an invalid memory address or nil pointer dereference


Banging my head on this one. I can't get an HTTP Response to assign to a struct.
I have my structs set up like so:
type DataConnect struct {
Response *Response
}
type Response struct {
response []byte
errors []string
}
Then the function in question is laid out like so (trimmed for readability):
137 func (d *DataConnect) send() bool {
...
154 out, err := ioutil.ReadAll(resp.Body)
155 if err != nil {
156 fmt.Println(err)
157 }
158
159 fmt.Printf("%s\n", out) // THIS WORKS
160 d.Response.response = out // THIS DOES NOT WORK
161 }
Doing that results in the following error:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x36532]
goroutine 1 [running]:
github.com/DataConnect.(*DataConnect).send(0xc2000af4a0, 0x232a00)
github.com/DataConnect/DataConnect.go:160 +0xc22
Now if I change DataConnect.Response.response to type interface{} I can save successfully to it, however I need it in []byte as later I will be doing a json.Unmarshal on the content.
Does anybody have any idea why this isn't working?
I suspect either d is nil or d.Response is nil on line 160. If that is true, you need to decide if that is appropriate and change your code if it is not.
I suspect #alex is correct, change your code to something that looks for nil (from line 159):
fmt.Printf("%s\n", out) // THIS WORKS
if d != nil && d.Response != nil {
d.Response.response = out // THIS DOES NOT WORK
} else {
// appropriate error logging and handling
}

Related Links

Datastore get not finding record by key
App Engine Search: How can I search multiple search indexes in parallel?
Task Queue in GAE JAVA - Battle Engine
What is the clear difference of a Ancestor Key and a Parent Key?
Calling Google Apps Script as webapp from AppEngine returns 405
How to tell whether it is a “development server”?
Why I got over quota error ? google app engine
If I use ObjectifyFilter I get error
Is there an API for creating google cloud platform credentials?
How to make programmatic access to an appengine application that is secure and authenticated
What App Engine datastore caching strategy will give complete cache consistency?
Google App Engine : High CPU Utilization
appengine cloud storage compile error in demo project
Issue with using the Google Datastore query console
How can I run `gcloud preview app setup-managed-vms` without this error?
Appengine unit test fail with Objectify - No Class registered

Categories

HOME
phpword
scikit-learn
sitecore
elasticsearch-5
augeas
mod-security
openbugs
modbus-tcp
powershell-v5.0
dimensional-modeling
shortest-path
cfml
dataflow-diagram
mongoid6
definitelytyped
interbase
mat
winexe
user-defined-functions
carrierwave
corenlp-server
left-join
quickfixj
installscript
slacktextviewcontroller
yowsup
engine.io
google-earth-engine
tex
metawidget
magento-1.9.3
doc
branching-and-merging
contract
clang++
apache-spark-dataset
oim
user-defined-fields
geotiff
tinkerpop
skin
rocks
redistributable
nikeplus-api
rspec2
gogs
vorpal.js
google-query-language
tracker-enabled-dbcontext
spreadjs
aurora
hadoop-partitioning
ellucian-scribe
invoke-sqlcmd
exim4
piracy-prevention
relativelayout
include-guards
extjs-grid
sapscript
zscript
nodelist
execve
webmatrix-3
teaspoon
ignite-ui
ora-00904
winginx
gae-quotas
ie8-compatibility-mode
mbunit
workitem
octal
joomla-template
video-codecs
onload-event
insert-id
chart-director
sqlclr
device-width
robotlegs
joomla3.1
mkv
nokia-s40
garbage
subproject
screen-size
winmain
presentation-layer
eclipse-marketplace
spread
filesystemobject
flvplayback

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile