impl

package module
v0.0.0-...-d6d383d Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2016 License: MIT Imports: 13 Imported by: 1

README

Declaration: this is a fork of https://github.com/josharian/impl, and some custom features have been added into.


impl generates method stubs for implementing an interface.

go get -u github.com/zjx20/impl

Sample usage:

$ impl 'f *File' io.ReadWriteCloser
func (f *File) Read(p []byte) (n int, err error) {
	panic("not implemented")
}

func (f *File) Write(p []byte) (n int, err error) {
	panic("not implemented")
}

func (f *File) Close() error {
	panic("not implemented")
}

# You can also provide a full name by specifying the package path.
# This helps in cases where the interface can't be guessed
# just from the package name and interface name.
$ impl 's *Source' golang.org/x/oauth2.TokenSource
func (s *Source) Token() (*oauth2.Token, error) {
    panic("not implemented")
}

impl could also be used as a package, see the sample code cli/impl.go or godoc for details.

Documentation

Overview

impl generates method stubs for implementing an interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(recv string, iface string, tmplString string) ([]byte, error)

Generate generates stubs for iface base on the tmplString.

func GenerateMethods

func GenerateMethods(recv string, fns []Func, tmplString string) ([]byte, error)

GenerateMethods generates code for fns with tmplString.

Types

type Func

type Func struct {
	Name    string
	Params  []Param
	Res     []Param
	Comment string
}

Func represents a function signature.

func Funcs

func Funcs(iface string) ([]Func, error)

Funcs returns the set of methods required to implement iface. It is called funcs rather than methods because the function descriptions are functions; there is no receiver.

func (*Func) String

func (fn *Func) String() string

type Method

type Method struct {
	Recv string
	Func
}

Method represents a method signature.

type Param

type Param struct {
	Name string
	Type string
}

Param represents a parameter in a function or method signature.

func (*Param) String

func (p *Param) String() string

type Pkg

type Pkg struct {
	*build.Package
	*token.FileSet
	*ast.File
}

Pkg is a parsed build.Package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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