github.com/searKing/golang/go@v1.2.117/container/traversal/handler.go (about) 1 // Copyright 2020 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 traversal 6 7 type Order func(node any, handler Handler) 8 9 type Handler interface { 10 Handle(node any, depth int) (goon bool) 11 } 12 13 // The HandlerFunc type is an adapter to allow the use of 14 // ordinary functions as traversal handlers. If f is a function 15 // with the appropriate signature, HandlerFunc(f) is a 16 // Handler that calls f. 17 type HandlerFunc func(node any, depth int) (goon bool) 18 19 // ServeHTTP calls f(w, r). 20 func (f HandlerFunc) Handle(node any, depth int) (goon bool) { 21 return f(node, depth) 22 } 23 24 type traversaler interface { 25 traversal(currents []levelNode, handler levelNodeHandler) (goon bool) 26 } 27 28 // The traversalerFunc type is an adapter to allow the use of 29 // ordinary functions as traversal handlers. If f is a function 30 // with the appropriate signature, HandlerFunc(f) is a 31 // Handler that calls f. 32 type traversalerFunc func(currents []levelNode, handler levelNodeHandler) (goon bool) 33 34 // ServeHTTP calls f(w, r). 35 func (f traversalerFunc) traversal(currents []levelNode, handler levelNodeHandler) (goon bool) { 36 return f(currents, handler) 37 } 38 39 type levelNodeHandler interface { 40 Handle(node levelNode) (goon bool) 41 } 42 43 // The levelNodeHandlerFunc type is an adapter to allow the use of 44 // ordinary functions as traversal handlers. If f is a function 45 // with the appropriate signature, HandlerFunc(f) is a 46 // Handler that calls f. 47 type levelNodeHandlerFunc func(node levelNode) (goon bool) 48 49 // ServeHTTP calls f(w, r). 50 func (f levelNodeHandlerFunc) Handle(node levelNode) (goon bool) { 51 return f(node) 52 }