common-iface

command module
v0.0.0-...-1a504a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2018 License: MIT Imports: 13 Imported by: 0

README

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).

Documentation

Overview

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL