Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.08 KB

README.md

File metadata and controls

41 lines (31 loc) · 1.08 KB

Recipe - Using the common I/O interfaces

The Go language provides a number of I/O interfaces that are used throughout the standard library. It is best practice to make use of these interfaces wherever possible rather than passing structures or other types directly.

type Reader interface {  
        Read(p []byte) (n int, err error)  
}

type Writer interface {  
        Write(p []byte) (n int, err error)  
}

Go makes it easy to combine interfaces.

type Seeker interface {  
        Seek(offset int64, whence int) (int64, error)  
}

type ReadSeeker interface {  
        Reader  
        Seeker  
}
func Pipe() (*PipeReader, *PipeWriter)