Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec struct{}
Codec is a Codec[[][]string] backed by encoding/csv. It is safe for concurrent use.
Example ¶
package main
import (
"fmt"
"github.com/foomo/goencode/csv"
)
func main() {
c := csv.NewCodec()
records := [][]string{
{"name", "age"},
{"Alice", "30"},
}
encoded, err := c.Encode(records)
if err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
fmt.Printf("Encoded: %s", string(encoded))
var decoded [][]string
if err := c.Decode(encoded, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded: %v\n", decoded)
}
Output: Encoded: name,age Alice,30 Decoded: [[name age] [Alice 30]]
type StreamCodec ¶
type StreamCodec struct{}
StreamCodec is a StreamCodec[[][]string] backed by encoding/csv. It is safe for concurrent use.
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/foomo/goencode/csv"
)
func main() {
c := csv.NewStreamCodec()
records := [][]string{
{"name", "age"},
{"Alice", "30"},
}
var buf bytes.Buffer
if err := c.Encode(&buf, records); err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
var decoded [][]string
if err := c.Decode(&buf, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded: %v\n", decoded)
}
Output: Decoded: [[name age] [Alice 30]]
func NewStreamCodec ¶
func NewStreamCodec() *StreamCodec
NewStreamCodec returns a CSV stream serializer.
Click to show internal directories.
Click to hide internal directories.