szabba / irgen

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

irgen is a code generator for the visitees (elements) in the visitor pattern.

Given a file option.go in the directory $GOPATH/src/some-domain.org/option containing

package option

//go:generate irgen Option OptionConsumer

type Option interface {
    FeedTo(consumer OptionConsumer)
}

type OptionConsumer interface {
    Some(X interface{})
    None()
}

running go generate some-domain.org/option will generate a file named option_impl.go containing something like

package option

type Some struct {
    X interface{}
}
type None struct {
}

func (option Some) FeedTo(consumer OptionConsumer) { consumer.Some(Option.X) }
func (option None) FeedTo(consumer OptionConsumer) { consumer.None() }

About

License:Mozilla Public License 2.0


Languages

Language:Go 100.0%