/godec

Decorator Fabricator

Primary LanguageGoMIT LicenseMIT

Build Status Go Report Card Documentation

Godec

Description

Godec is decorator fabricator. Godec will automatically create a decorator for desired interface using desired template. The desired template must be placed in folder template/.

Installation

go install github.com/bukalapak/godec/app/godec

Usage

  1. Add go:generate hook in desired file

    //go:generate godec MyInterface canceler
    type MyInterface interface {
      Sample(int, string) (float64, error)
    }

    godec needs two or more arguments to run correctly.

    godec [interface name] [decorator name]...

    [interface name] is the name of interface to be decorated. In the example above, interface's name is MyInterface. [decorator name] is the name of decorator. In the example above, decorator's name is canceler. Please, note that desired decorator must be placed in template/ folder. Godec will find the desired template there. The name of the template decorator must be <name>.go.tmpl. Please, look at template/ for clarity.

  2. Run go generate

    go generate

    Decorator will be created in folder decorator/.