// ChainInterceptors chains multiple Interceptors into a single Interceptor.
// The first interceptor wraps the second one, and so on.
// Returns nil if interceptors is empty. Nil interceptors are ignored.
ChainInterceptors chains multiple Interceptors into a single Interceptor.
The first interceptor wraps the second one, and so on.
Returns nil if interceptors is empty. Nil interceptors are ignored.
// ChainInterceptors chains multiple Interceptors into a single Interceptor . // The first interceptor wraps the second one and so on . // Returns nil if interceptors is empty . Nil interceptors are ignored .
func ChainInterceptors(interceptors ...Interceptor) Interceptor {
	filtered := make([]Interceptor, 0, len(interceptors))
	for _, interceptor := range interceptors {
		if interceptor != nil {
			filtered = append(filtered, interceptor)
		}
	}
	switch n := len(filtered); n {
	case 0:
		return nil
	case 1:
		return filtered[0]
	default:
		first := filtered[0]
		return func(next Method) Method {
			for i := len(filtered) - 1; i > 0; i-- {
				next = filtered[i](next)
			}
			return first(next)
		}
	}
}
func ChainInterceptors ( interceptors ... Interceptor ) Interceptor { filtered := make ( [ ] Interceptor , 0 , len ( interceptors ) ) for _ , interceptor := range interceptors { if interceptor != nil { filtered = append ( filtered , interceptor ) } } switch n := len ( filtered ) ; n { case 0 : return nil case 1 : return filtered [ 0 ] default : first := filtered [ 0 ] return func ( next Method ) Method { for i := len ( filtered ) - 1 ; i > 0 ; i -- { next = filtered [ i ] ( next ) } return first ( next ) } } }
ChainInterceptors chains multiple Interceptors into a single Interceptor.
ChainInterceptors chains multiple Interceptors into a single Interceptor .