37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ui.go 1019 Bytes
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-01-24 00:19 . Package UI
package ui
import (
"io"
"net/http"
"os"
"github.com/rancher/norman/parse"
"github.com/sirupsen/logrus"
)
var uiURL = "https://releases.rancher.com/ui/latest2/index.html"
func Content() http.Handler {
return http.FileServer(http.Dir("ui"))
}
func UI(next http.Handler) http.Handler {
local := false
_, err := os.Stat("ui/index.html")
if err == nil {
local = true
}
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
if parse.IsBrowser(req, true) {
if local {
http.ServeFile(resp, req, "ui/index.html")
} else {
ui(resp, req)
}
} else {
next.ServeHTTP(resp, req)
}
})
}
func ui(resp http.ResponseWriter, req *http.Request) {
if err := serveIndex(resp, req); err != nil {
logrus.Errorf("failed to serve UI: %v", err)
resp.WriteHeader(500)
}
}
func serveIndex(resp http.ResponseWriter, req *http.Request) error {
r, err := http.Get(uiURL)
if err != nil {
return err
}
defer r.Body.Close()
_, err = io.Copy(resp, r.Body)
return err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.0-alpha11

搜索帮助