Thank you Alex for the link. Will check it out.

To further clarify, the issue I am having is with:

opts …func(*procStruct)
opts …func(*sysStruct)

I have multiple structs other than *procStruct (as listed in the example), 
so I am trying to find the best way to generalize this parameter so I can 
have a common parameter for my factories. 

Here is a reference link for the pattern I am using for inspiration:

http://matthewbrown.io/2016/01/23/factory-pattern-in-golang/

As you can see in the above link, the factories use a common parameter.. 
however, I am trying to adapt this for functional options.

Thank you for the reply!



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.

Reply via email to