mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-22 12:46:03 +03:00
idiom/functional-options: fix formatting and naming
This commit is contained in:
parent
065ae23a2f
commit
066d2f6b42
@ -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__:
|
||||||
|
|
||||||
|
@ -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 {
|
Loading…
Reference in New Issue
Block a user