Skip to content
romanyxPublic

About

generates an adapter for a specified interface

Resources

Stars

10 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

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

About

generates an adapter for a specified interface

Resources

Stars

10 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

⌂ 换网址