add observer

This commit is contained in:
ginuerzh
2024-01-03 20:55:06 +08:00
parent e1ae379048
commit c959fc2f73
95 changed files with 2371 additions and 890 deletions

32
stats/wrapper/listener.go Normal file
View File

@ -0,0 +1,32 @@
package wrapper
import (
"net"
"github.com/go-gost/x/stats"
)
type listener struct {
stats *stats.Stats
net.Listener
}
func WrapListener(ln net.Listener, stats *stats.Stats) net.Listener {
if stats == nil {
return ln
}
return &listener{
stats: stats,
Listener: ln,
}
}
func (ln *listener) Accept() (net.Conn, error) {
c, err := ln.Listener.Accept()
if err != nil {
return nil, err
}
return WrapConn(c, ln.stats), nil
}