Documentation
¶
Overview ¶
Example ¶
var enc Encoder
var err error
enc = GNjson{Pretty: true}
ary1 := []int{1, 2, 3}
jsonRes, err := enc.Encode(ary1)
if err != nil {
panic(err)
}
var ary2 []int
err = enc.Decode(jsonRes, &ary2)
if err != nil {
panic(err)
}
fmt.Println(ary1[0] == ary2[0])
Output: true
Index ¶
- func NormRowSize(row []string, fieldsNum int) []string
- func Ppr(obj interface{}) string
- func ReadHeaderCSV(path string, sep rune) (map[string]int, error)
- func TimeString(secs float64) string
- func ToCSV(record []string, sep rune) string
- type BadRow
- type Encoder
- type Format
- type GNgob
- type GNjson
- type Outputter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormRowSize ¶ added in v0.4.4
NormRowSize takes a row with less or more fields than required and either truncates it, or expands with empty fields to fit to the fieldsNum size.
func ReadHeaderCSV ¶
ReadHeaderCSV only reads the first line of a CSV/TSV input. It takes a path to a CSV/TSV-encoded file and a separator character. It returns back a map with name of a field, and its index. It also returns an error, if the header could not be read.
func TimeString ¶ added in v0.4.0
Types ¶
type BadRow ¶ added in v0.4.5
type BadRow int
BadRow type describes different scenarios of processing rows with wrong number of fields.
const ( // ErrorBadRow means that an error will be returned when a row with wrong // number of fields is encountered. ErrorBadRow BadRow = iota // SkipBadRow means that rows with wrong number of fields will not be // processed. SkipBadRow // ProcessBadRow means processing bad row hoping for the best. ProcessBadRow )
type Encoder ¶
type Encoder interface {
//Encode takes a Go object and converts it into bytes
Encode(input interface{}) ([]byte, error)
// Decode takes an input of bytes and decodes it into Go object.
Decode(input []byte, output interface{}) error
}
Encoder interface allows to switch between different encoding types.
type Format ¶
type Format int
Format sets available output formats
const ( // FormatNone is for cases when format is not set yet. FormatNone Format = iota // CSV sets output to comma-separated values. CSV // CompactJSON sets output into one-liner JSON. CompactJSON // PrettyJSON sets output into easier to read JSON with new lines and // indentations. PrettyJSON // TSV sets output to tab-separated values. TSV )
type GNgob ¶
type GNgob struct{}
GNgob is for serializing data into gob format.
type GNjson ¶
type GNjson struct {
Pretty bool
}
GNjson allows to decode and encode JSON format.
func (GNjson) Decode ¶
Decode converts JSON into a go object. If decoding breaks, it returns an error.