generates an adapter for a specified interface
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml
LICENSE
README.md
adapt.go
adapt_test.go
go.mod
go.sum
interfaces_stub.go

README.md

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