Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ClientMetaHandler = client.WithMetaHandler(&MetaTTHeaderHandler{})
View Source
var ErrClientHandlerOption = client.WithErrorHandler(func(ctx context.Context, err error) error { transErr, ok := err.(*remote.TransError) if ok && transErr.TypeID() == 6 { errStr := strings.ReplaceAll(transErr.Error(), "biz error: ", "") var errInfo e.Err err = json.Unmarshal([]byte(errStr), &errInfo) if err == nil { return errInfo } err = e.RPCClientErrorCodeError.SetErr(err, strings.ReplaceAll(transErr.Error(), "biz error: ", "")) } else { err = e.RPCClientErrorCodeError.SetErr(err, "数据访问失败") } return err })
ErrClientHandlerOption 业务错误再封装
View Source
var ErrHandlerOption = client.WithErrorHandler(func(ctx context.Context, err error) error { transErr, ok := err.(*remote.TransError) if ok && transErr.TypeID() == 6 { err = e.RPCClientErrorCodeError.SetErr(err, strings.ReplaceAll(transErr.Error(), "biz error: ", "")) } else { statusErr, ok := err.(*status.Error) if ok && uint32(statusErr.GRPCStatus().Code()) == 13 { err = e.RPCClientErrorCodeError.SetErr(err, strings.TrimSpace(strings.ReplaceAll(statusErr.GRPCStatus().Message(), "[biz error]", ""))) } else { err = e.RPCClientErrorCodeError.SetErr(err, "数据访问失败") } } return err })
ErrHandlerOption 业务错误再封装
View Source
var ErrServerHandlerOption = server.WithErrorHandler(func(ctx context.Context, err error) error { transErr, ok := err.(*kerrors.DetailedError) if ok { var errInfo e.Err if transErr.As(&errInfo) { var b []byte b, err = json.Marshal(errInfo) if err != nil { err = e.RPCServerErrorCodeError.SetErr(err, "错误转换失败") } else { err = e.RPCServerErrorCodeError.SetErr(err, string(b)) } } } else { err = e.RPCServerErrorCodeError.SetErr(err, "数据访问失败") } return err })
View Source
var GrpcTokenKey struct{}
View Source
var GrpcTokenStringKey = "grpcTokenString"
View Source
var ServerMetaHandler = server.WithMetaHandler(&MetaTTHeaderHandler{})
Functions ¶
Types ¶
type GrpcToken ¶
type GrpcToken struct {
GrpcToken string `json:"grpcToken"`
}
func (GrpcToken) GetGrpcToken ¶
type GrpcTokenGet ¶
type GrpcTokenGet interface {
GetGrpcToken() string
}
Click to show internal directories.
Click to hide internal directories.