Thank you Alex. To further clarify, what I am trying to do is create factory methods that return a common interface. In a nutshell, I am trying to create constructors that take a common argument.
As it stands, the parameter I specify is very specific (function with a pointer to a struct): opts …func(*procStruct) So end goal is to try to generalize the parameter (if possible), so when I add more factory functions I can associate them with a particular type known as plugin. Also, thanks for the link.. going to take a look. On Wednesday, October 11, 2017 at 12:22:55 PM UTC-7, Alex Buchanan wrote: > > I'm not sure I understand the example, but have you seen the grpc > library's use of options? For more type safety, you could define an > interface such as type PluginOpt interface { pluginOpt() }. > > https://godoc.org/google.golang.org/grpc#CallOption > > On Wednesday, October 11, 2017 at 11:23:16 AM UTC-7, Frank Ruiz wrote: >> >> Greetings, >> >> Was hoping to solicit some feedback on utilizing functional options in >> conjunction with factory methods. >> >> I currently have the following function: >> >> func ProcPlugin(opts …func(*procStruct){ >> p := defaulProc >> for _, opt := range opts { >> opt(&p) >> } >> return &p, nil >> } >> >> I am now trying to generalize things (as I will be creating more factory >> functions), and I'm trying to determine if this is the most optimal way to >> represent the logic above. >> >> type PluginFactory func(opts ...interface{}) (Plugin, error) >> >> func NewProcPlugin(opts ...interface{}) (Plugin, error) { >> p := defaulProc >> for _, opt := range opts { >> opt(&p) >> } >> return &p, nil >> } >> >> Any feedback would be much appreciated. Please let me know if more >> context is required. >> >> Thank you! >> > -- 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.