package connection // ConnectionInterface 连接接口(统一所有连接类型) type ConnectionInterface interface { ID() string RemoteAddr() string LocalAddr() string Write(data []byte) error Close() error } // ToConnectionInterface 将各种连接类型转换为统一接口 func ToConnectionInterface(conn interface{}) ConnectionInterface { switch c := conn.(type) { case *Connection: return c case *UDPConnection: return c case *WebSocketConnection: return c case *UnixConnection: return c case *SerialConnection: return c default: return nil } }