代码拉取完成,页面将自动刷新
同步操作将从 lunny/tango 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// Copyright 2015 The Tango Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tango
import (
"fmt"
"net/http"
)
// AbortError defines an interface to describe HTTP error
type AbortError interface {
error
Code() int
}
type abortError struct {
code int
content string
}
func (a *abortError) Code() int {
return a.code
}
func (a *abortError) Error() string {
return fmt.Sprintf("%v", a.content)
}
// Abort returns an AbortError
func Abort(code int, content ...string) AbortError {
if len(content) >= 1 {
return &abortError{code, content[0]}
}
return &abortError{code, http.StatusText(code)}
}
// NotFound returns not found HTTP error
func NotFound(content ...string) AbortError {
return Abort(http.StatusNotFound, content...)
}
// NotSupported returns not supported HTTP error
func NotSupported(content ...string) AbortError {
return Abort(http.StatusMethodNotAllowed, content...)
}
// InternalServerError returns internal server HTTP error
func InternalServerError(content ...string) AbortError {
return Abort(http.StatusInternalServerError, content...)
}
// Forbidden returns forbidden HTTP error
func Forbidden(content ...string) AbortError {
return Abort(http.StatusForbidden, content...)
}
// Unauthorized returns unauthorized HTTP error
func Unauthorized(content ...string) AbortError {
return Abort(http.StatusUnauthorized, content...)
}
// Errors returns default errorhandler, you can use your self handler
func Errors() HandlerFunc {
return func(ctx *Context) {
switch res := ctx.Result.(type) {
case AbortError:
ctx.WriteHeader(res.Code())
ctx.WriteString(res.Error())
case error:
ctx.WriteHeader(http.StatusInternalServerError)
ctx.WriteString(res.Error())
default:
ctx.WriteHeader(http.StatusInternalServerError)
ctx.WriteString(http.StatusText(http.StatusInternalServerError))
}
}
}
// ErrorWithCode descripts an error that with error code
type ErrorWithCode interface {
error
ErrorCode() int
}
type ErrorKeyIsNotExist struct {
Key string
}
func (e ErrorKeyIsNotExist) Error() string {
return fmt.Sprintf("Key %s is not exist", e.Key)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。