Documentation ¶
Overview ¶
Example (It_is_error) ¶
package main import ( "fmt" "github.com/chen56/go-common/grpc/statusx" ) func main() { var err error = statusx.NotFound("user不存在: %s", "chen").Err() fmt.Println(err) }
Output: NotFound: user不存在: chen
Example (RetryInfo) ¶
package main import ( "context" "fmt" "github.com/chen56/go-common/grpc/statusx" "github.com/golang/protobuf/ptypes/duration" "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/genproto/googleapis/rpc/errdetails" "net/http" "net/http/httptest" ) func main() { fmt.Println(toJson(statusx.Unavailable("暂时不能服务,稍后再试").WithRetryInfo(&errdetails.RetryInfo{ RetryDelay: &duration.Duration{ Seconds: 1, }, }))) } func toJson(err *statusx.Status) string { ctx := context.Background() w := httptest.NewRecorder() req, _ := http.NewRequest("", "", nil) runtime.DefaultHTTPError(ctx, &runtime.ServeMux{}, &runtime.JSONPb{}, w, req, err.Err()) return w.Body.String() }
Output: {"error":"暂时不能服务,稍后再试","message":"暂时不能服务,稍后再试","code":14,"details":[{"@type":"type.googleapis.com/google.rpc.RetryInfo","retryDelay":"1s"}]}
Index ¶
- func Try(f func() error) (err error)
- type Status
- func Aborted(msgAndArgs ...interface{}) *Status
- func AlreadyExists(msgAndArgs ...interface{}) *Status
- func Canceled(msgAndArgs ...interface{}) *Status
- func DataLoss(msgAndArgs ...interface{}) *Status
- func DeadlineExceeded(msgAndArgs ...interface{}) *Status
- func FailedPrecondition(msgAndArgs ...interface{}) *Status
- func FromError(err error) *Status
- func FromStatus(status *status.Status) *Status
- func Internal(msgAndArgs ...interface{}) *Status
- func InvalidArgument(msgAndArgs ...interface{}) *Status
- func MapIfStdError(err error, newError func(err error) *Status) *Status
- func NotFound(msgAndArgs ...interface{}) *Status
- func OutOfRange(msgAndArgs ...interface{}) *Status
- func PermissionDenied(msgAndArgs ...interface{}) *Status
- func ResourceExhausted(msgAndArgs ...interface{}) *Status
- func Unauthenticated(msgAndArgs ...interface{}) *Status
- func Unavailable(msgAndArgs ...interface{}) *Status
- func Unimplemented(msgAndArgs ...interface{}) *Status
- func Unknown(msgAndArgs ...interface{}) *Status
- func (x *Status) Code() codes.Code
- func (x *Status) Err() error
- func (x *Status) GRPCStatus() *status.Status
- func (x *Status) Message() string
- func (x *Status) RetryInfo() *errdetails.RetryInfo
- func (x *Status) WithDebugError(err error) *Status
- func (x *Status) WithDebugMessage(debugMsgAndArgs ...interface{}) *Status
- func (x *Status) WithDetails(details ...proto.Message) *Status
- func (x *Status) WithRetryInfo(retryInfo *errdetails.RetryInfo) *Status
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
func AlreadyExists ¶
func AlreadyExists(msgAndArgs ...interface{}) *Status
func DeadlineExceeded ¶
func DeadlineExceeded(msgAndArgs ...interface{}) *Status
func FailedPrecondition ¶
func FailedPrecondition(msgAndArgs ...interface{}) *Status
func FromStatus ¶
func InvalidArgument ¶
func InvalidArgument(msgAndArgs ...interface{}) *Status
func MapIfStdError ¶
MapIfStdError 如果参数err是普通的error(而不是errorsg包的Error),则 用newError转换为新error
func OutOfRange ¶
func OutOfRange(msgAndArgs ...interface{}) *Status
func PermissionDenied ¶
func PermissionDenied(msgAndArgs ...interface{}) *Status
func ResourceExhausted ¶
func ResourceExhausted(msgAndArgs ...interface{}) *Status
func Unauthenticated ¶
func Unauthenticated(msgAndArgs ...interface{}) *Status
func Unavailable ¶
func Unavailable(msgAndArgs ...interface{}) *Status
func Unimplemented ¶
func Unimplemented(msgAndArgs ...interface{}) *Status
func (*Status) GRPCStatus ¶
func (*Status) RetryInfo ¶
func (x *Status) RetryInfo() *errdetails.RetryInfo
func (*Status) WithDebugError ¶
func (*Status) WithDebugMessage ¶
func (*Status) WithRetryInfo ¶
func (x *Status) WithRetryInfo(retryInfo *errdetails.RetryInfo) *Status
Click to show internal directories.
Click to hide internal directories.