sequence

This paper mainly studies the recoveryFilter of Dubo-Go-proxy

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{} }Copy the code

RecoveryFilter registers recoveryFilterFunc with extension named dgp.filters. Recovery. This func executes the Do method of recoveryFilter

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() } }Copy the code

The Do method first registers a defer func to recover and then executes c.next ()

summary

Dubo-go-proxy recoveryFilter registers a defer func to recover, and then executes c.next ().

doc

  • dubbo-go-proxy