go - how handle error in http.Get in function -


i have problem whith function:

func execute(query query) (goreq.response, error) {      res, err := goreq.request{         uri:         "http://path/to/host",         querystring: query,         accept:      "application/json",         useragent:   "xxxgoclient/1.0",         timeout:     2000 * time.millisecond,         compression: goreq.gzip(),         //showdebug:   true,     }.do()      return *res, err } 

i getting panic: runtime error: invalid memory address or nil pointer dereference when error in http request ocurrs.

i know check this:

if err != nil {     // somthing here } 

but dont know must do, example this:

if err != nil {     return } 

i ./main.go:113: not enough arguments return

i'm not used http requests in go, guess error comes '*res' 'res' nil when there's error.

what i'd return pointer (*goreq.response), avoiding dereference:

func execute(query query) (*goreq.response, error) {     return goreq.request{        // original code goes here     }.do() } 

in case dereference pointer value of response needed , can ignored if error not nil.

hope helps.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -