An open API service indexing awesome lists of open source software.

https://github.com/hankjacobs/gointerfacegen

Go tool for generating interfaces from a type
https://github.com/hankjacobs/gointerfacegen

go golang interface tool

Last synced: 11 months ago
JSON representation

Go tool for generating interfaces from a type

Awesome Lists containing this project

README

          

# gointerfacegen

A Go tool used to generate an interface from a type's methods.

## Installation

```bash
go get github.com/hankjacobs/gointerfacegen
```

## Usage

```text
gointefacegen

Generates an interface from the type's methods found in the specified file. File must be valid go source.
If the interface already exists, it is updated in place.
Default behavior prints the resulting file with the new or updated interface to standard out.

Examples:
gointefacegen somecustomtype somecustominterface src.go

-i Print only interface to standard out. This takes precedence over -w flag
-w Write result to file instead of stdout
```

## Example

Given a file `demo.go`:

```go
package demo

type example struct {
}

func (t example) First() {
}

func (t example) Second(one, two string) (named example, other example) {
return
}

```

running:

```shell
gointerfacegen example ExampleInterface demo.go
```

will produce:

```go
package demo

type ExampleInterface interface {
First()
Second(one, two string) (example, example)
}

type example struct {
}

func (t example) First() {
}

func (t example) Second(one, two string) (named example, other example) {
return
}
```