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

https://github.com/alex-leonhardt/go-decorator-pattern

golang and decorators / decorator patterns
https://github.com/alex-leonhardt/go-decorator-pattern

decorator-pattern golang learn-to-code learning-go learning-golang programming-exercise

Last synced: 3 months ago
JSON representation

golang and decorators / decorator patterns

Awesome Lists containing this project

README

        

## golang and the decorator pattern

a playground for me (and maybe helpful for others?) to train the brain understand the decorator pattern better

- a basic function decorator, see [example1](example1/)
- a basic timing decorator (how long does func X take?), see [example2](example2/)
- decorating a method (think OOP), see [example3](example3/)
- another method decorator, but using a Func type, useful when the func signature is rather long, see [example4](example4/)
- method decorator that takes arguments [example5](example5/)
- return the result from the decorated function, instead of printing it [example6](example6/)
- a logging decorator, see [example7](example7/)
- a nested decorator example, see [example8](example8/)
- passing data to a http handler is a little weird (to me), but a fully working example is here: [go-web-random](https://github.com/alex-leonhardt/go-web-random/blob/master/main.go#L25-L35)
- let's play with a interface [example9](example9/)

## contribute

pull requests are welcomed