聊聊dubbo-go-proxy的recoveryFilter

Posted codecraft

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了聊聊dubbo-go-proxy的recoveryFilter相关的知识,希望对你有一定的参考价值。

本文主要研究一下dubbo-go-proxy的recoveryFilter

recoveryFilter

dubbo-go-proxy/pkg/filter/recovery/recovery.go

func Init() {
    extension.SetFilterFunc(constant.RecoveryFilter, recoveryFilterFunc())
}

func recoveryFilterFunc() context.FilterFunc {
    return New().Do()
}

// recoveryFilter is a filter for recover.
type recoveryFilter struct {
}

// New create timeout filter.
func New() filter.Filter {
    return &recoveryFilter{}
}
recoveryFilter往extension注册名为dgp.filters.recovery的recoveryFilterFunc;该func执行的是recoveryFilter的Do方法

Do

dubbo-go-proxy/pkg/filter/recovery/recovery.go

// Recovery execute recoveryFilter filter logic, if recover happen, print log or do other things.
func (f recoveryFilter) Do() context.FilterFunc {
    return func(c context.Context) {
        defer func() {
            if err := recover(); err != nil {
                logger.Warnf("[dubboproxy go] error:%+v", err)

                c.WriteErr(err)
            }
        }()
        c.Next()
    }
}
Do方法先注册一个defer func进行recover,然后再执行c.Next()

小结

dubbo-go-proxy的recoveryFilter注册一个defer func进行recover,然后再执行c.Next()。

doc

  • dubbo-go-proxy

以上是关于聊聊dubbo-go-proxy的recoveryFilter的主要内容,如果未能解决你的问题,请参考以下文章

聊聊dubbo-go-proxy的ConsulRegistryLoad

聊聊dubbo-go-proxy的ParamMapper

聊聊dubbo-go-proxy的ZookeeperRegistryLoad

聊聊dubbo-go-proxy的authorityFilter

聊聊dubbo-go-proxy的Client

聊聊dubbo-go-proxy的Route