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
将文件复制到golang中的stdin时出错_Go_Dokku - Fatal编程技术网

将文件复制到golang中的stdin时出错

将文件复制到golang中的stdin时出错,go,dokku,Go,Dokku,我正在使用echo为dokku管理构建一个web应用程序。它有一个url路由器要处理,我的处理程序如下: 包路由器 import ( "fmt" "github.com/labstack/echo" "io" "net/http" "os/exec" ) // deploy app via tar file func deployTarApp(c echo.Context) error { name := c.Param("name")

我正在使用echo为dokku管理构建一个web应用程序。它有一个url路由器要处理,我的处理程序如下: 包路由器

import (
    "fmt"
    "github.com/labstack/echo"
    "io"
    "net/http"
    "os/exec"
)

// deploy app via tar file
func deployTarApp(c echo.Context) error {
    name := c.Param("name")
    file, ef := c.FormFile("file")
    if ef != nil || file == nil {
        return c.NoContent(http.StatusBadRequest)
    }
    tempfile, et := file.Open()
    if et != nil {
        return c.JSON(http.StatusInternalServerError, et)
    }
    cmd := exec.Command(DokkuPath, "tar:in", name)
    stdin, err := cmd.StdinPipe()
    if err != nil {
        return c.JSON(http.StatusInternalServerError, err)
    }
    go func() {
        defer stdin.Close()
        io.Copy(stdin, tempfile)
    }()
    out, e := cmd.CombinedOutput()
    if e != nil {
        fmt.Println(string(out), e)
        return c.JSON(http.StatusInternalServerError, e)
    }
    return c.NoContent(http.StatusOK)
}
首先获取表单文件,然后将其复制到stdin,然后运行
dokku tar:in-app name
。但是代码抛出了一个错误

/var/lib/dokku/plugins/available/git/functions: line 114: /home/dokku/node-sample/refs/heads/master: No such file or directory
 exit status 128

处理程序有什么问题?我是刚来戈朗的,所以对它不太熟悉。感谢您的帮助。

第114行是什么?@nicovank打印并观察变量
DokkuPath
name
的内容。确保在shell中执行命令时没有错误。@putu
DokkuPath
的值是
/usr/bin/dokku
name
是一个不为空的字符串值(app name)。我确信命令是正确的,下面的命令在shell中正确执行
cat./express-sample-master.tar | dokku tar:in node sample
它抱怨
/home/dokku/node sample/refs/heads/master
不可用。确保请求的文件可用。此外,请确保您的web应用程序具有访问该文件的权限。作为比较,您可以创建相关代码的命令行版本,然后在shell中执行它。