摘要: 好处是配置可选,直观 type Server struct { Addr string Port int protocol string Timeout time.Duration MaxConn int TLS *tls.Config } type option func(*Server) fun 阅读全文
posted @ 2022-02-24 20:25 故意写bug 阅读(141) 评论(0) 推荐(0)
摘要: /* UndoIntSet是IntSet的功能扩展,可以进行undo操作 通过委托和反转控制将IntSet的逻辑和Undo的逻辑分开 undo的功能由委托给functions,这样可以实现IntSet依赖functions, */ type undo []func() func (u *undo) 阅读全文
posted @ 2022-02-24 20:17 故意写bug 阅读(200) 评论(0) 推荐(0)
摘要: 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){ fm 阅读全文
posted @ 2022-02-24 20:08 故意写bug 阅读(114) 评论(0) 推荐(0)
摘要: //产生数据 func makeData(min,max int)[]int{ data := make([]int,max-min+1) for i := range data{ data[i]=min+i } return data } //把输入的数据通过通道传递出去 func echo(nu 阅读全文
posted @ 2022-02-24 19:59 故意写bug 阅读(159) 评论(0) 推荐(0)
摘要: ##visitor模式 //先定义一个需要访问的数据结构 type Info struct { Namespace string Name string OtherThings string } type VisitorFunc func(*Info,error)error //将访问数据的方法抽象 阅读全文
posted @ 2022-02-24 19:51 故意写bug 阅读(91) 评论(0) 推荐(0)