I've found a solution, but it's not as nice as interfaces:
Injectable function type:
func(l *eventlog.Log, eid uint32, msg string) error
Struct methods convert directly to this type without wrappers: (*
eventlog.Log).Info and (*eventlog.Log).Error
On Tuesday, May 22, 2018 at 12:46:28 PM UTC+2, e
Let's say I want to unit test code that is using
eventlog.Open: https://godoc.org/golang.org/x/sys/windows/svc/eventlog#Open
First I define an interface that matches eventlog.Log:
type WindowsEventLogger interface {
Info(eid uint32, msg string) error
Error(eid uint32, msg string) error
}
>
> P.S. someone else proposed wrapper with error handling in defer.
> IMO it is as bad as watch - spooky, at distance, clunky.
>
That was me. My background is many years of C++ and it feels natural to me
(RAII). I follow the pattern: there must be defer Close immediately after
acquire action
I've been doing something like this for long chains where "handle error" is
the same:
func something() (x int, err error) {
defer func() {
if err != nil {
// handle error
}
}()
res, err = acquireResource()
if err == nil {
defer func() {