You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
583 B
Go
29 lines
583 B
Go
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
|
|
}
|
|
}
|