Skip to content

common-iface is a small utility that prints out a Go interface type representing the common interface of the types passed on the command line.

License

Notifications You must be signed in to change notification settings

fvbommel/common-iface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

common-iface GoDoc

common-iface is a small utility that prints out an interface type representing the common interface of the types passed on the command line.

For example, suppose you want to parse some data from either memory (contained in a bytes.Reader) or a buffered network connection (bufio.Reader). You want to know what methods will be available, so you run:

$ common-iface bytes.Reader bufio.Reader
interface {
    Read(b []byte) (n int, err error)
    ReadByte() (byte, error)
    ReadRune() (ch rune, size int, err error)
    UnreadByte() error
    UnreadRune() error
    WriteTo(w io.Writer) (n int64, err error)
}

Or if you want to be able to handle both files and network connections:

$ common-iface os.File net.Conn
interface {
    Close() error
    Read(b []byte) (n int, err error)
    SetDeadline(t time.Time) error
    SetReadDeadline(t time.Time) error
    SetWriteDeadline(t time.Time) error
    Write(b []byte) (n int, err error)
}

This can then e.g. be copy-pasted into a source file to define a local interface type (and optionally trimmed down to remove unused methods).

About

common-iface is a small utility that prints out a Go interface type representing the common interface of the types passed on the command line.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages