adapt

command module
v0.0.0-...-1312fe9 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 18 Imported by: 0

README

Build Status

adapt generates adapter type to allow the use of ordinary functions as the interface.

go get -u github.com/romanyx/adapt

You can pass package and interface names to generate adapter:

$ adapt io Reader
type readerFunc func([]byte) (int, error)

func (f readerFunc) Read(p []byte) (int, error) {
	return f(p)
}

You also can call adapt inside a package folder to generate adapter for some of its interfaces:

$ cd $GOPATH/src/github.com/romanyx/polluter Polluter
$ adapt Polluter
type polluterFunc func(io.Reader) error

func (f polluterFunc) Pollute(r io.Reader) error {
	return f(r)
}

It comes in handy for Unit testing with table driven tests.

You can use adapt from Vim with vim-go-adapt

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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