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 | | 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__: __Anti-Patterns__:

View File

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