Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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
&引用;没有这样的文件或目录;使用Go 1.13实现Google云功能_Go_Google Cloud Platform_Google Cloud Functions - Fatal编程技术网

&引用;没有这样的文件或目录;使用Go 1.13实现Google云功能

&引用;没有这样的文件或目录;使用Go 1.13实现Google云功能,go,google-cloud-platform,google-cloud-functions,Go,Google Cloud Platform,Google Cloud Functions,我用Go编写了一个Google云函数,并使用Go 1.11运行时进行了部署,它可以正常工作。将运行时升级到Go 1.13时出现问题,使用相同的函数,我得到以下错误: Error: could not handle the request 在云函数的日志中,我有这些错误的详细信息: Function execution started open ./progress.html: no such file or directory Function execution took 232 ms, f

我用Go编写了一个Google云函数,并使用Go 1.11运行时进行了部署,它可以正常工作。将运行时升级到Go 1.13时出现问题,使用相同的函数,我得到以下错误:

Error: could not handle the request
在云函数的日志中,我有这些错误的详细信息:

Function execution started
open ./progress.html: no such file or directory
Function execution took 232 ms, finished with status: 'connection error'
文件在那里,与Go文件位于同一文件夹中

以下是该功能的相关代码:

// Progress ... Entrypoint of our Cloud Function
func Progress(w http.ResponseWriter, r *http.Request) {
        
        ...

        tpl, err := template.ParseFiles("progress.html")
        if err != nil {
            log.Fatalln(err)
        }

        buf := new(bytes.Buffer)

        err = tpl.Execute(buf, data)
        if err != nil {
            log.Fatalln(err)
        }
       ...
    }
gcloud functions deploy progress --runtime go113 --entry-point Progress --trigger-http --memory 128MB
如果有帮助的话,这个功能是什么

唯一改变的是用于部署它的Go运行时,从1.11到1.13

以下是用于部署它的两个命令:

它的工作原理是:

gcloud functions deploy progress --runtime go111 --entry-point Progress --trigger-http --memory 128MB
它不工作(它已成功部署,但在使用该函数时出现错误):


错误是假设使用不同运行时的Google云函数实现相同,但通过调试,我发现了一些差异

以下是调试它的测试函数:

func Progress(w http.ResponseWriter, r *http.Request) {
    wd, _ := os.Getwd()
    fmt.Fprintf(w, "$> pwd\n%s\n\n", wd)
  
    bytes, _ = exec.Command("ls", "-l").CombinedOutput()
    fmt.Fprintf(w, "$> ls -l\n%s\n\n", bytes)
}
以下是使用Go 1.11运行时的输出:

$> pwd
/srv/files/

$> ls -l
total 5
-rw-r--r-- 1 root root 1068 Aug 13 04:15 LICENSE
-rw-r--r-- 1 root root 1097 Aug 13 04:15 README.md
drwxr-xr-x 2 root root    0 Aug 13 04:15 colors-example
-rw-r--r-- 1 root root 2093 Aug 13 04:15 progress.go
-rw-r--r-- 1 root root  627 Aug 13 04:15 progress.html
如您所见,所有文件都在当前目录中,包括缺少的文件
progress.html

但以下是使用Go 1.13运行时的输出:

$> pwd
/srv

$> ls -l
total 0
drwxr-xr-x 2 www-data www-data 0 Jan  1  1980 pkg
drwxr-xr-x 2 www-data www-data 0 Jan  1  1980 src
注意我的文件已经不在了,所以我打印了
src
的内容,并包含一个名为
progress
(我的项目名称)的文件夹

在那个文件夹里,有我所有的文件

因此,使用Go 1.13运行时时的修复是:

// Progress ... Entrypoint of our Cloud Function
func Progress(w http.ResponseWriter, r *http.Request) {
        
        ...

        tpl, err := template.ParseFiles("src/progress/progress.html")
        if err != nil {
            log.Fatalln(err)
        }

        buf := new(bytes.Buffer)

        err = tpl.Execute(buf, data)
        if err != nil {
            log.Fatalln(err)
        }
       ...
    }

我希望它能帮助某些人,不仅是为了答案,而且如果新运行时的规则发生了变化,那么您就有办法调试它并找到文件的正确位置。

这是的副本吗?似乎不是。这个问题的答案让我觉得它指的是Go运行时的一个旧版本,那个文件夹已经不存在了。但是谢谢你链接它,它给了我一个测试内容的提示。谢谢你的解释,但是这个解决方案已经不起作用了。对我来说很有效