package main import ( "fmt" "strings" ) /** 链式处理函数 */ func StringProcess(list [] string,chain [] func(string) string) { for index,str:=range list{ result:=str for _,proc:=range chain{ result=proc(result) } list[index]=result } } // 自定义移除前缀 func removePrefix(str string) string{ return strings.TrimPrefix(str,"go") } func main(){ // 定义list list:=[] string { "go abc","go dad","go go"," yaode"," youyou", } // 定义函数处理 调用链 chain:=[]func (string) string{ removePrefix, strings.TrimSpace, strings.ToUpper, } // 调用链式处理函数 StringProcess(list,chain) // 循环输出list for _,str:=range list{ fmt.Println(str) } }