Closed matthewvalimaki closed 7 years ago
Hi @matthewvalimaki - thanks for the report, that example is indeed busted right now!
DoRequest
needs to remain concurrency-safe wrt Client
, so I'm going to update Init
to use http.DefaultClient
if one isn't already set, and return an error from Client.DoRequest
if Client.Client
(heh) is nil
, instead of panicking.
I did copy & paste from README example and got a segfault:
The cause of this is https://github.com/SparkPost/gosparkpost/blob/master/common.go#L196 and the fact that README never initializes the
c.Client
unlike its unit test https://github.com/SparkPost/gosparkpost/blob/master/common_test.go#L30.If I modify
common.go
line 196 tothe segfault goes away.
My suggestions are: 1) Append tests to include what README does. 2) Apply my
common.go
modification to guarantee client existence. Note that asc.Client
is exported it can be set outside ofinit
and thus my modification inDoRequest
. Or perhaps makeClient
beclient
and force use ofNewClient()
which would then always doreturn &client{Client: http.DefaultClient}
.