I'm using Go on GAE. One of my tasks is sending an email. I am using this documentation successfully to test.
However, what if I do not want a request handler:
func confirm(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
...
But rather, send the email through a local func:
func confirm() {
...
Is there any way in Go to do this with GAE? I think what Im looking for is a way to call:
c := appengine.NewContext(r)
But without a request handler, or bypass it in any way possible (which Im reading is probably not possible)
I am thinking a work around could be making an http request from my application to my application - but wow is that ugly!
resp, err := http.Get("http://localhost:8080/sendMail?to=...")
NOTE: After attempting this -- ugly work around I get: http.DefaultTransport and http.DefaultClient are not available in App Engine. See https://cloud.google.com/appengine/docs/go/urlfetch/
So this workaround is in fact NOT a work around in that urlfetch
which is how GAE uses http.GET once again... requires c := appengine.NewContext(r)
You need an appengine.Context to interact with external services, including email and urlfetch. You will have to pass the Context instance into your confirm
function.