Skip to content

Instantly share code, notes, and snippets.

@joncalhoun
Last active October 11, 2018 01:57
Show Gist options
  • Save joncalhoun/9418747124d974274a037cd75315bac9 to your computer and use it in GitHub Desktop.
Save joncalhoun/9418747124d974274a037cd75315bac9 to your computer and use it in GitHub Desktop.
type Messenger struct {
// Add this field here
Client *http.Client
mux *http.ServeMux
messageHandlers []MessageHandler
deliveryHandlers []DeliveryHandler
readHandlers []ReadHandler
postBackHandlers []PostBackHandler
optInHandlers []OptInHandler
referralHandlers []ReferralHandler
accountLinkingHandlers []AccountLinkingHandler
token string
verifyHandler func(http.ResponseWriter, *http.Request)
verify bool
appSecret string
}
// Then add this helper method - it is technically NOT threadsafe, but only if you try to change the Client field
// while you are using it to make requests in another goroutine.
func (m *Messenger) httpClient() *http.Client {
if m.Client != nil {
return m.Client
}
return &http.Client{}
}
// Then in your methods...
func (m *Messenger) ProfileByID(id int64) (Profile, error) {
// ... all the same
// change this line
client := m.httpClient()
resp, err := client.Do(req)
// ... all the same
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment