Thanks a lot Sam. A follow up question, what's the Go way of naming such functions?
Java would name it like "somethingFactory", C# would name it like "GetHelloFunction". what's the typical Go naming, for a factory function that generates Hello handling function? thx On Tuesday, August 7, 2018 at 8:37:45 AM UTC-4, Sam Whited wrote: > > You'd want to use a function that returns another function and takes the > dependencies as arguments, something like this: > > func Sender(b *B) func(m *tb.Message) { > return func(m *tb.Message) { > b.Send(m.Sender, "hello world") > } > } > > s := Sender(b) > b.Handle("/hello", s) > b.Handle("/hi", s) > > > —Sam > > On Tue, Aug 7, 2018, at 07:29, Tong Sun wrote: > > Hi, > > > > Consider this function: > > > > b.Handle("/hello", func(m *tb.Message) { > > b.Send(m.Sender, "hello world") > > }) > > > > > > I tried to refactor the above function to func sayHi(m *tb.Message) > {...}, > > so that I can give an alias to the above /hello command (say to define > a > > /hi command), but found that I cannot use bwithin it any more. > > > > So, how to refactor out this function? > > > -- > Sam Whited > s...@samwhited.com <javascript:> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.