Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 转到新上下文_Google App Engine_Go - Fatal编程技术网

Google app engine 转到新上下文

Google app engine 转到新上下文,google-app-engine,go,Google App Engine,Go,我在用Go on GAE。我的任务之一是发送电子邮件。我正在成功地使用文档进行测试 但是,如果我不需要请求处理程序,该怎么办 func confirm(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) ... 而是通过本地func发送电子邮件: func confirm() { ... 有没有办法让GAE这么做?我想我要找的是一种叫: c :=

我在用Go on GAE。我的任务之一是发送电子邮件。我正在成功地使用文档进行测试

但是,如果我不需要请求处理程序,该怎么办

func confirm(w http.ResponseWriter, r *http.Request) {
        c := appengine.NewContext(r)
                    ...
而是通过本地func发送电子邮件:

func confirm() {
...
有没有办法让GAE这么做?我想我要找的是一种叫:

c := appengine.NewContext(r)
但是没有请求处理程序,或者以任何可能的方式绕过它(Im读取可能是不可能的)

我在想一个变通办法可能会让我的应用程序与我的应用程序之间产生冲突——但哇,真是太难看了

resp, err := http.Get("http://localhost:8080/sendMail?to=...")
注意:在尝试了这个——丑陋的工作环境后,我得到: http.DefaultTransport和http.DefaultClient在应用程序引擎中不可用。看


因此,这个解决方法实际上不是GAE再次使用http.GET的
urlfetch
中的解决方法。。。需要
c:=appengine.NewContext(r)

您需要一个appengine.Context来与外部服务交互,包括电子邮件和urlfetch。您必须将上下文实例传递到
confirm
函数中

我担心这就是答案。除了*http.Request之外,还有其他方法可以传递给它吗?还是某种类型的假*http.Request?如果可能的话,我尽量不使用请求处理程序。谢谢。我不确定你的目标是什么,但如果没有先启动实例的请求,app engine根本不会运行任何代码,因此即使你可以这样做,也无法让代码执行。你想要解决的具体需求是什么?哦,啊,啊,啊+1。我不知道,但它回答了我的问题!非常感谢您的支持