github.com/blend/go-sdk@v1.20240719.1/web/middleware.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package web 9 10 // Middleware is a func that implements middleware 11 type Middleware func(Action) Action 12 13 // NestMiddleware reads the middleware variadic args and organizes the calls 14 // recursively in the order they appear. I.e. NestMiddleware(inner, third, 15 // second, first) will call "first", "second", "third", then "inner". 16 func NestMiddleware(action Action, middleware ...Middleware) Action { 17 if len(middleware) == 0 { 18 return action 19 } 20 21 a := action 22 for _, i := range middleware { 23 if i != nil { 24 a = i(a) 25 } 26 } 27 return a 28 }