Go Gen Interface: Simple Go Interface Generator
Generate Go interfaces from structs and their methods.
// FROM THIS
package example
type A struct{}
func (a *A) FuncA(i1 int, i2 string) {
panic("not implemented")
}
func (a *A) FuncB() (int, error) {
panic("not implemented")
}
// TO THIS
type A interface {
FuncA(i1 int, i2 string)
FuncB() (int, error)
}
Installation
go get github.com/siraphobk/go-gen-interface
Usage
go run github.com/siraphobk/go-gen-interface [COMMAND] [FLAGS]...
Interface Generation
The program reads a directory of Go files. It finds all structs and their methods, then generate an interface of those structs.
Interface generator is a CLI program. You can see all the available commands and flags by running go run main.go --help
.
Examples
Generate interfaces from structs
Run make run_example
, then see result in example/gen-interface
.
Initialize configuration file for interface generation
Run make run_example_init
, then see result in example/gen-interface-init
.
Roadmap
- Interface generator reads configuration from config file
- Allow adding prefix and suffix to interfaces
- Implement struct generator