douzhi1972 2017-04-26 02:15
浏览 51

将文件错误复制到Golang中的stdin

I'm using echo to build a web app for dokku management. It has a url router to handle tarfile deploying and my handler is bellow: package routers

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)
}

First get the form file, then copy it to stdin, then run dokku tar:in app-name. But the code throws an error

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

What is the problem with the handler? I am new to golang, so I am not so familiar with it. Thanks for your help.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 WPF使用Canvas绘制矢量图问题
    • ¥15 用三极管设计一个单管共射放大电路
    • ¥15 孟德尔随机化r语言运行问题
    • ¥15 pyinstaller编译的时候出现No module named 'imp'
    • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
    • ¥15 怎么把多于硬盘空间放到根目录下
    • ¥15 Matlab问题解答有两个问题
    • ¥15 LCD12864中文显示
    • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
    • ¥15 gsoap生成onvif框架