https://github.com/bukalapak/godec
Decorator Fabricator
https://github.com/bukalapak/godec
decorator decorator-pattern decorators go golang
Last synced: 12 months ago
JSON representation
Decorator Fabricator
- Host: GitHub
- URL: https://github.com/bukalapak/godec
- Owner: bukalapak
- License: mit
- Created: 2018-07-17T04:38:48.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-23T09:19:51.000Z (almost 8 years ago)
- Last Synced: 2024-06-20T15:42:48.603Z (about 2 years ago)
- Topics: decorator, decorator-pattern, decorators, go, golang
- Language: Go
- Size: 19.5 KB
- Stars: 3
- Watchers: 9
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/bukalapak/godec)
[](https://goreportcard.com/report/github.com/bukalapak/godec)
[](http://godoc.org/github.com/bukalapak/godec)
# 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/](https://github.com/bukalapak/godec/tree/master/template).
## Installation
```sh
go install github.com/bukalapak/godec/app/godec
```
## Usage
1. Add `go:generate` hook in desired file
```go
//go:generate godec MyInterface canceler
type MyInterface interface {
Sample(int, string) (float64, error)
}
```
godec needs two or more arguments to run correctly.
```sh
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/](https://github.com/bukalapak/godec/tree/master/template) folder. Godec will find the desired template there. The name of the template decorator must be `.go.tmpl`. Please, look at [template/](https://github.com/bukalapak/godec/tree/master/template) for clarity.
2. Run `go generate`
```sh
go generate
```
Decorator will be created in folder `decorator/`.