1
0
mirror of https://github.com/tmrts/go-patterns.git synced 2024-11-23 21:46:08 +03:00

idiom/functional-options: fix formatting and naming

This commit is contained in:
Tamer Tas 2016-09-06 19:12:24 +03:00
parent 065ae23a2f
commit 066d2f6b42
2 changed files with 5 additions and 1 deletions

View File

@ -104,7 +104,7 @@ __Idioms__:
| Pattern | Description |
|:-------:| ----------- |
| [Functional Options](idiom/functional_options.md) | Allows creating clean APIs with sane defaults and idiomatic overrides |
| [Functional Options](idiom/functional-options.md) | Allows creating clean APIs with sane defaults and idiomatic overrides |
__Anti-Patterns__:

View File

@ -1,10 +1,12 @@
# Functional Options
Functional options are a method of implementing clean/eloquent APIs in Go.
Options implemented as a function set the state of that option.
## Implementation
### Options
```go
package file
@ -44,6 +46,7 @@ func Permissions(perms os.FileMode) Option {
```
### Constructor
```go
package file
@ -77,6 +80,7 @@ func New(filepath string, setters ...Option) error {
```
## Usage
```go
emptyFile, err := file.New("/tmp/empty.txt")
if err != nil {