-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds ability to conditionally include headers for CSV files
- Loading branch information
Showing
8 changed files
with
151 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package csv | ||
|
||
type Options func(*Client) | ||
|
||
// Client is a csv client. | ||
type Client struct { | ||
IncludeHeaders bool | ||
Delimiter rune | ||
} | ||
|
||
func NewClient(options ...Options) (*Client, error) { | ||
c := &Client{ | ||
Delimiter: ',', | ||
} | ||
for _, option := range options { | ||
option(c) | ||
} | ||
|
||
return c, nil | ||
} | ||
|
||
func WithHeader() Options { | ||
return func(c *Client) { | ||
c.IncludeHeaders = true | ||
} | ||
} | ||
|
||
func WithDelimiter(delimiter rune) Options { | ||
return func(c *Client) { | ||
c.Delimiter = delimiter | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package json | ||
|
||
type Option func(*Client) | ||
|
||
type Client struct{} | ||
|
||
func NewClient(options ...Option) (*Client, error) { | ||
c := &Client{} | ||
for _, option := range options { | ||
option(c) | ||
} | ||
|
||
return c, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters