37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
common_util.go 946 Bytes
一键复制 编辑 原始数据 按行查看 历史
Craig Jellick 提交于 2018-02-05 11:27 . Refactor auth code
package util
import (
"encoding/json"
"net/http"
"strconv"
)
//ReturnHTTPError handles sending out Error response
// TODO Use the Norman API error framework instead
func ReturnHTTPError(w http.ResponseWriter, r *http.Request, httpStatus int, errorMessage string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(httpStatus)
err := AuthError{
Status: strconv.Itoa(httpStatus),
Message: errorMessage,
Type: "error",
}
enc := json.NewEncoder(w)
enc.SetEscapeHTML(false)
enc.Encode(err)
}
func GetHTTPErrorCode(httpStatus int) string {
switch httpStatus {
case 401:
return "Unauthorized"
case 404:
return "NotFound"
case 403:
return "PermissionDenied"
case 500:
return "ServerError"
}
return "ServerError"
}
//AuthError structure contains the error resource definition
type AuthError struct {
Type string `json:"type"`
Status string `json:"status"`
Message string `json:"message"`
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.0-rc15

搜索帮助

0d507c66 1850385 C8b1a773 1850385