github.com/searKing/golang/go@v1.2.117/net/http/handler.go (about)

     1  // Copyright 2022 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package http
     6  
     7  import "net/http"
     8  
     9  // HandlerDecorator is an interface representing the ability to decorate or wrap a http.Handler.
    10  type HandlerDecorator interface {
    11  	WrapHandler(rt http.Handler) http.Handler
    12  }
    13  
    14  // HandlerDecorators defines a HandlerDecorator slice.
    15  type HandlerDecorators []HandlerDecorator
    16  
    17  func (chain HandlerDecorators) WrapHandler(next http.Handler) http.Handler {
    18  	for i := range chain {
    19  		h := chain[len(chain)-1-i]
    20  		if h != nil {
    21  			next = h.WrapHandler(next)
    22  		}
    23  	}
    24  	return next
    25  }