1 Star 0 Fork 0

煮酒品天下/go-fresh

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.go 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
Andrea Franz 提交于 2014-01-15 22:24 +08:00 . initial import
package runnerutils
import (
"bufio"
"html/template"
"io/ioutil"
"net/http"
"os"
"path/filepath"
)
var logFilePath string
func init() {
root := os.Getenv("RUNNER_WD")
tmpPath := os.Getenv("RUNNER_TMP_PATH")
fileName := os.Getenv("RUNNER_BUILD_LOG")
logFilePath = filepath.Join(root, tmpPath, fileName)
}
// Returns true if a build error file exists in the tmp folder.
func HasErrors() bool {
if _, err := os.Stat(logFilePath); err == nil {
return true
}
return false
}
// It renders an error page with the build error message.
func RenderError(w http.ResponseWriter) {
data := map[string]interface{}{
"Output": readErrorFile(),
}
w.Header().Set("Content-Type", "text/html")
tpl := template.Must(template.New("ErrorPage").Parse(buildPageTpl))
tpl.Execute(w, data)
}
func readErrorFile() string {
file, err := os.Open(logFilePath)
if err != nil {
return ""
}
defer file.Close()
reader := bufio.NewReader(file)
bytes, _ := ioutil.ReadAll(reader)
return string(bytes)
}
const buildPageTpl string = `
<html>
<head>
<title>Traffic Panic</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
html, body{ padding: 0; margin: 0; }
header { background: #C52F24; color: white; border-bottom: 2px solid #9C0606; }
h1 { padding: 10px 0; margin: 0; }
.container { margin: 0 20px; }
.output { height: 300px; overflow-y: scroll; border: 1px solid #e5e5e5; padding: 10px; }
</style>
</head>
<body>
<header>
<div class="container">
<h1>Build Error</h1>
</div>
</header>
<div class="container">
<pre class="output">{{ .Output }}</pre>
</div>
</body>
</html>
`
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/werde/go-fresh.git
git@gitee.com:werde/go-fresh.git
werde
go-fresh
go-fresh
0fa698148017

搜索帮助