fix(observer): add nil guards, fix resource leak, silent event drops, and missing doc comments

- WrapUDPConn, WrapPacketConn, WrapListener: add nil guards for pc/ln params
- NewGRPCPlugin: return no-op observer instead of nil on connection error
- gRPC plugin: fix resource leak by wiring Close() through observerWrapper
  and service.Close() lifecycle
- Both plugins: log unknown event types instead of silently dropping them
- httpPlugin: remove dead nil check for always-non-nil client field
- Stats.Reset: update core interface doc to match implementation behavior
- Add doc comments to all exported symbols across the observer package
This commit is contained in:
ginuerzh
2026-05-24 23:13:52 +08:00
parent bc3d12ec2c
commit 7c95d40e05
8 changed files with 58 additions and 4 deletions
+13
View File
@@ -2,6 +2,7 @@ package registry
import (
"context"
"io"
"github.com/go-gost/core/observer"
)
@@ -37,3 +38,15 @@ func (w *observerWrapper) Observe(ctx context.Context, events []observer.Event,
}
return v.Observe(ctx, events, opts...)
}
// Close closes the underlying observer if it implements io.Closer.
func (w *observerWrapper) Close() error {
v := w.r.get(w.name)
if v == nil {
return nil
}
if closer, ok := v.(io.Closer); ok {
return closer.Close()
}
return nil
}