github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/rw/duplex.go (about) 1 package rw 2 3 import ( 4 "github.com/sagernet/sing/common" 5 ) 6 7 type ReadCloser interface { 8 CloseRead() error 9 } 10 11 type WriteCloser interface { 12 CloseWrite() error 13 } 14 15 func CloseRead(reader any) error { 16 if c, ok := common.Cast[ReadCloser](reader); ok { 17 return c.CloseRead() 18 } 19 return nil 20 } 21 22 func CloseWrite(writer any) error { 23 if c, ok := common.Cast[WriteCloser](writer); ok { 24 return c.CloseWrite() 25 } 26 return nil 27 }