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.

Reply via email to