Documentation
¶
Overview ¶
Helpers that makes it easy to build CSV dialects. This API is currently in alpha. Feel free to discuss it on https://github.com/jensrantil/go-csv/issues.
Example (Flag) ¶
package main
import (
"flag"
csv "github.com/JensRantil/go-csv"
"github.com/JensRantil/go-csv/dialect"
"os"
)
func main() {
builder := dialect.FromCommandLine()
flag.Parse()
dialect, err := builder.Dialect()
if err != nil {
panic(err)
}
reader := csv.NewDialectWriter(os.Stdout, *dialect)
reader.Write([]string{"Hello", "World"})
reader.Flush()
}
Output: Hello World
Example (FlagSet) ¶
package main
import (
"flag"
csv "github.com/JensRantil/go-csv"
"github.com/JensRantil/go-csv/dialect"
"os"
)
func main() {
fset := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
builder := dialect.FromFlagSet(fset)
fset.Parse([]string{})
dialect, err := builder.Dialect()
if err != nil {
panic(err)
}
reader := csv.NewDialectWriter(os.Stdout, *dialect)
reader.Write([]string{"Hello", "World"})
reader.Flush()
}
Output: Hello World
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DialectBuilder ¶
type DialectBuilder struct {
// contains filtered or unexported fields
}
func FromCommandLine ¶
func FromCommandLine() *DialectBuilder
Construct a CSV Dialect from command line using the `flag` package. This is three steps: First, call this function and store the handler. Optionally register other flags. Call `flag.Parse()`. A dialect can then be constructed by calling `DialectBuilder.Dialect()`.
func FromFlagSet ¶
func FromFlagSet(f *flag.FlagSet) *DialectBuilder
Constructs a CSV Dialect from a specific flagset. Essentially the same as `FromCommandLine()`, except it supports a custom FlagSet. See `FromCommandLine()` for a description on how to use this one.
Click to show internal directories.
Click to hide internal directories.