Skip to content

Commit

Permalink
Publish blog on configuring options in Go, closes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
rednafi committed Sep 5, 2023
1 parent 3d70526 commit 376c40f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion content/go/configure_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,18 @@ The complete snippet looks as follows:
```go
package src

// We can keep style private
type style struct {
fg string
bg string
und bool // Optional field
zigzag bool // Optional field
}

// This can be priave too since the users won't need it directly
type styleoption func(*style)

// We only define config functions for the optional fields
// We only define public config functions for the optional fields
func WithUnd(und bool) styleoption {
return func(s *style) {
s.und = true
Expand All @@ -247,6 +249,7 @@ func WithZigzag(zigzag bool) styleoption {
}
}

// Options are variadic but the required fiels must be passed
func NewStyle(fg, bg string, options ...styleoption) *style {
s := &style{fg, bg, false, false}
for _, opt := range options {
Expand Down

0 comments on commit 376c40f

Please sign in to comment.