csv

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 3 Imported by: 0

README

csv

import "github.com/kitsunium/sdk/pkg/v1/data/codec/csv"

Package csv registers the CSV codec with the SDK's codec registry — and no other codec — when it is imported (ADR 0134):

import _ "github.com/kitsunium/sdk/pkg/v1/data/codec/csv"

The codec is the standard library's encoding/csv over RFC 4180 records: its native value is a [][]string, the rows of a table, or a slice of structs — a header from the fields' csv tags, then one record per row, each cell converted to its field. Through the codec package's Marshal any other value is carried as its JSON, in the one cell of a one-column table, and read back the same way. It streams: one record per Decode and Encode.

Everything that dispatches through the registry by format name then reads and writes it: the codec package's Marshal and Unmarshal, config.FSSource and i18n.LoadFS. Importing github.com/kitsunium/sdk/pkg/v1/data/codec instead registers every format the SDK ships; this package links this one codec, the core package declaring its codes and the standard library, and nothing else. Importing both is harmless: a format is registered by the package that implements it, which Go initialises once however many packages import it.

Errors

Failures carry the range 0.3.8.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeMarshalFailed    0.3.8.1  encoding/csv refused to write the records
CodeUnmarshalFailed  0.3.8.2  the input is not CSV encoding/csv reads
CodeValueInvalid     0.3.8.3  the value or the target is not a [][]string or a table of structs
CodeHeaderMismatch   0.3.8.4  the header lacks a required column, or repeats one
CodeCellInvalid      0.3.8.5  a cell does not convert to its field's type
CodeOptionsInvalid   0.3.8.6  NewWithOptions was given an invalid delimiter

No error message quotes the input.

Index

Constants

const CodeCellInvalid errs.Code = 198661

CodeCellInvalid is 0.3.8.5: a cell does not convert to its field's type.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.CodeCSVCellInvalid.

Code 0.3.8.5

const CodeHeaderMismatch errs.Code = 198660

CodeHeaderMismatch is 0.3.8.4: the header lacks a column the struct requires, or repeats one it maps.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.CodeCSVHeaderMismatch.

Code 0.3.8.4

const CodeMarshalFailed errs.Code = 198657

CodeMarshalFailed is 0.3.8.1: encoding/csv refused to write the records.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.CodeCSVMarshalFailed.

Code 0.3.8.1

const CodeOptionsInvalid errs.Code = 198662

CodeOptionsInvalid is 0.3.8.6: options with a delimiter encoding/csv cannot use.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.CodeCSVOptionsInvalid.

Code 0.3.8.6

const CodeUnmarshalFailed errs.Code = 198658

CodeUnmarshalFailed is 0.3.8.2: the input is not CSV encoding/csv reads.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.CodeCSVUnmarshalFailed.

Code 0.3.8.2

const CodeValueInvalid errs.Code = 198659

CodeValueInvalid is 0.3.8.3: the value or the target is not a [][]string.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.CodeCSVValueInvalid.

Code 0.3.8.3

const Format = "csv"

Format is the name CSV is registered under. It is an untyped constant, so it goes wherever a format name is taken — the codec package's Marshal, config.FSSource's string, i18n.LoadFS's codec.Format — without a conversion.

Variables

var CellInvalid *errs.Error

CellInvalid is the sentinel of CodeCellInvalid.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.CellInvalid.

Code 0.3.8.5 · reason CELL_INVALID · public "CSV cell does not convert to its column's type"

var HeaderMismatch *errs.Error

HeaderMismatch is the sentinel of CodeHeaderMismatch.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.HeaderMismatch.

Code 0.3.8.4 · reason HEADER_MISMATCH · public "CSV header does not match the expected columns"

var MarshalFailed *errs.Error

MarshalFailed is the sentinel of CodeMarshalFailed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.MarshalFailed.

Code 0.3.8.1 · reason MARSHAL_FAILED · public "CSV encoding failed"

var OptionsInvalid *errs.Error

OptionsInvalid is the sentinel of CodeOptionsInvalid.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.OptionsInvalid.

Code 0.3.8.6 · reason OPTIONS_INVALID · public "CSV options are invalid"

var UnmarshalFailed *errs.Error

UnmarshalFailed is the sentinel of CodeUnmarshalFailed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.UnmarshalFailed.

Code 0.3.8.2 · reason UNMARSHAL_FAILED · public "CSV decoding failed"

var ValueInvalid *errs.Error

ValueInvalid is the sentinel of CodeValueInvalid.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/csv.ValueInvalid.

Code 0.3.8.3 · reason VALUE_INVALID · public "CSV codec requires a [][]string value"

Generated from docs/api by tools/genindex.

Documentation

Overview

Package csv registers the CSV codec with the SDK's codec registry — and no other codec — when it is imported (ADR 0134):

import _ "github.com/kitsunium/sdk/pkg/v1/data/codec/csv"

The codec is the standard library's encoding/csv over RFC 4180 records: its native value is a [][]string, the rows of a table, or a slice of structs — a header from the fields' csv tags, then one record per row, each cell converted to its field. Through the codec package's Marshal any other value is carried as its JSON, in the one cell of a one-column table, and read back the same way. It streams: one record per Decode and Encode.

Everything that dispatches through the registry by format name then reads and writes it: the codec package's Marshal and Unmarshal, config.FSSource and i18n.LoadFS. Importing github.com/kitsunium/sdk/pkg/v1/data/codec instead registers every format the SDK ships; this package links this one codec, the core package declaring its codes and the standard library, and nothing else. Importing both is harmless: a format is registered by the package that implements it, which Go initialises once however many packages import it.

Errors

Failures carry the range 0.3.8.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeMarshalFailed    0.3.8.1  encoding/csv refused to write the records
CodeUnmarshalFailed  0.3.8.2  the input is not CSV encoding/csv reads
CodeValueInvalid     0.3.8.3  the value or the target is not a [][]string or a table of structs
CodeHeaderMismatch   0.3.8.4  the header lacks a required column, or repeats one
CodeCellInvalid      0.3.8.5  a cell does not convert to its field's type
CodeOptionsInvalid   0.3.8.6  NewWithOptions was given an invalid delimiter

No error message quotes the input.

Index

Constants

View Source
const (
	// CodeMarshalFailed is 0.3.8.1: encoding/csv refused to write the records.
	CodeMarshalFailed errs.Code = corecsv.CodeCSVMarshalFailed
	// CodeUnmarshalFailed is 0.3.8.2: the input is not CSV encoding/csv reads.
	CodeUnmarshalFailed errs.Code = corecsv.CodeCSVUnmarshalFailed
	// CodeValueInvalid is 0.3.8.3: the value or the target is not a
	// [][]string.
	CodeValueInvalid errs.Code = corecsv.CodeCSVValueInvalid
	// CodeHeaderMismatch is 0.3.8.4: the header lacks a column the struct
	// requires, or repeats one it maps.
	CodeHeaderMismatch errs.Code = corecsv.CodeCSVHeaderMismatch
	// CodeCellInvalid is 0.3.8.5: a cell does not convert to its field's type.
	CodeCellInvalid errs.Code = corecsv.CodeCSVCellInvalid
	// CodeOptionsInvalid is 0.3.8.6: options with a delimiter encoding/csv cannot use.
	CodeOptionsInvalid errs.Code = corecsv.CodeCSVOptionsInvalid
)

The error codes, range 0.3.8.*, declared in the core (ADR 0160).

View Source
const Format = "csv"

Format is the name CSV is registered under. It is an untyped constant, so it goes wherever a format name is taken — the codec package's Marshal, config.FSSource's string, i18n.LoadFS's codec.Format — without a conversion.

Variables

View Source
var (
	// MarshalFailed is the sentinel of [CodeMarshalFailed].
	MarshalFailed = corecsv.MarshalFailed
	// UnmarshalFailed is the sentinel of [CodeUnmarshalFailed].
	UnmarshalFailed = corecsv.UnmarshalFailed
	// ValueInvalid is the sentinel of [CodeValueInvalid].
	ValueInvalid = corecsv.ValueInvalid
	// HeaderMismatch is the sentinel of [CodeHeaderMismatch].
	HeaderMismatch = corecsv.HeaderMismatch
	// CellInvalid is the sentinel of [CodeCellInvalid].
	CellInvalid = corecsv.CellInvalid
	// OptionsInvalid is the sentinel of [CodeOptionsInvalid].
	OptionsInvalid = corecsv.OptionsInvalid
)

The sentinels, for errors.Is: each carries the code of the same name.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL