标签:return middle app war ... ret div tar ddl
package main
import (
"fmt"
_ "math/rand"
_ "time"
)
type EndPoint func(req interface{}) interface{}
type Middleware func(EndPoint) EndPoint
func Chain(others ...Middleware) Middleware {
return func(e EndPoint) EndPoint {
for i := len(others) - 1; i >= 0; i-- {
e = others[i](e)
}
return e
}
}
func genMiddleware(i int) Middleware {
return func(next EndPoint) EndPoint {
fmt.Println("flag...", i)
return next
}
}
func StartMain() {
var mids []Middleware
for i := 10; i > 0; i-- {
mids = append(mids, genMiddleware(i))
}
mid := Chain(mids...)
e := func(request interface{}) interface{} {
fmt.Println("start...")
return nil
}
finalfun := mid(e)
finalfun(3)
finalfun(3)
}
golang串联编程
标签:return middle app war ... ret div tar ddl
原文地址:http://www.cnblogs.com/datakv/p/7152631.html