grpcmid

package
v1.3.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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"

Functions

func WhiteIpMiddleware

func WhiteIpMiddleware(whiteList map[string][]string) server.Option

Types

type GrpcToken

type GrpcToken struct {
	GrpcToken string `json:"grpcToken"`
}

func (GrpcToken) GetGrpcToken

func (gt GrpcToken) GetGrpcToken() string

type GrpcTokenGet

type GrpcTokenGet interface {
	GetGrpcToken() string
}

type MetaTTHeaderHandler

type MetaTTHeaderHandler struct {
	WhiteApi   []string //接口白名单
	CheckWhite bool
}

func (*MetaTTHeaderHandler) ReadMeta

ReadMeta of MetaTTHeaderHandler reads headers of TTHeader protocol from transport

func (*MetaTTHeaderHandler) WriteMeta

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL