golang设计模式(三)装饰器模式
func decorator(f func(s1 string))func(s2 string) {
return func(s3 string) {
fmt.Println("start")
f(s3)
fmt.Println("end")
}
}
func hello(s string){
fmt.Println(s)
}
func main(){
decorator(hello)("hello")
}
func decorator(f func(s1 string))func(s2 string) {
return func(s3 string) {
fmt.Println("start")
f(s3)
fmt.Println("end")
}
}
func hello(s string){
fmt.Println(s)
}
func main(){
decorator(hello)("hello")
}