go-errhttp/upgraderequired.go

53 lines
1.1 KiB
Go
Raw Normal View History

2017-02-06 20:58:13 +00:00
package errhttp
import (
"net/http"
)
var _ Error = internalUpgradeRequired{}
var _ ClientError = internalUpgradeRequired{}
var _ UpgradeRequired = internalUpgradeRequired{}
var ClientErrorUpgradeRequired ClientError = UpgradeRequiredWrap(nil).(UpgradeRequired)
var ErrHTTPUpgradeRequired Error = ClientErrorUpgradeRequired
var ErrUpgradeRequired error = ClientErrorUpgradeRequired
2017-02-06 20:58:13 +00:00
type UpgradeRequired interface {
ClientError
UpgradeRequired()
}
type internalUpgradeRequired struct {
err error
}
func UpgradeRequiredWrap(err error) error {
return internalUpgradeRequired{
err:err,
}
}
func (receiver internalUpgradeRequired) Error() string {
2023-10-01 02:30:28 +00:00
err := receiver.err
if nil == err {
return http.StatusText(receiver.ErrHTTP())
}
return err.Error()
2017-02-06 20:58:13 +00:00
}
func (internalUpgradeRequired) ErrHTTP() int {
return http.StatusUpgradeRequired
}
2017-02-06 20:58:13 +00:00
func (internalUpgradeRequired) ClientError() {
// Nothing here.
}
func (internalUpgradeRequired) UpgradeRequired() {
// Nothing here.
}
func (receiver internalUpgradeRequired) Unwrap() error {
return receiver.err
}