As Far as I See, you check all the combinations of methods in wideness 
order.
Why not have a generic wrapper struct, that is filled with the underlying 
driver.Conn's methods, 
and use that if not nil, but use the generic implementation if not.

Like
```
type wrappedConn struct {
  driver.Conn
  queryContext func(...)
}
func (wc wrappedConn) QueryContext(...) ... {
  if wc.queryContext != nil { return wc.queryContext(...) }
  return wc.Conn.Query(...)
}
```

This way you only have to check for each method on driver.Conn, and fill 
the wrappedConn's functions as they axist/not.

Vasiliy Tolstov a következőt írta (2023. június 10., szombat, 12:16:34 
UTC+2):

> I have sql driver that wraps original driver.Driver, to be able to work 
> with drivers that not have ExecerContext or QuerierContext i need to return 
> wrapped to that supports only needed interfaces.
> I'm to want to write all cases via handmade switch case and write 
> generator that creates full combo list of methods and generate interfaces 
> for this methods.
> But this brings file that contains 20K lines 
> https://git.unistack.org/unistack-org/micro-wrapper-sql/src/branch/master/wrap_gen.go
> Does it possible to have smaller code that provides the same effect?
> Or I'm miss something?
>
> -- 
> Vasiliy Tolstov,
> e-mail: v.to...@selfip.ru
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/711d305c-7c4b-405e-9932-74dcc1ae8603n%40googlegroups.com.

Reply via email to