Documentation ¶
Overview ¶
Package text parses entities from textual input like CSV or TSV files.
Index ¶
- func FieldsExample(typ seed.Entity) string
- func InputExample(typ seed.Entity, format Format) string
- func ListFields(typ seed.Entity, html bool) map[string]string
- func ParseSetCommands(cmds []string, typ seed.Entity) ([][2]string, error)
- func Read(ctx context.Context, r io.Reader, format Format, typ seed.Entity, ...) ([]seed.Edit, error)
- func SetExample(typ seed.Entity) string
- func SetField(edit seed.Edit, field, val string) error
- type Format
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldsExample ¶
FieldsExample returns an example value for the web interface's "fields" input.
func InputExample ¶
InputExample returns an example value for the web interface's "input" textarea.
func ListFields ¶
ListFields returns a map from the names of fields that can be passed to Read for typ to human-readable descriptions. If html is true, links in descriptions are rewritten to HTML links.
func ParseSetCommands ¶
ParseSetCommands parses "field=val" commands into pairs and validates that they can be used to set fields on a seed.Edit of the supplied type.
func Read ¶
func Read(ctx context.Context, r io.Reader, format Format, typ seed.Entity, fields []string, rawSetCmds []string, db *mbdb.DB, opts ...Option) ([]seed.Edit, error)
Read reads one or more edits of the specified type from r in the specified format. fields specifies the field associated with each column (unused for the KeyVal format). Multiple fields can be associated with a single column by separating their names with slashes, and empty field names indicate that the column should be ignored. rawSets contains "field=value" directives describing values to set for all edits.
func SetExample ¶
SetExample returns an example value for the web interface's "set" textarea.
Types ¶
type Format ¶
type Format string
Format represents a textual format for supplying seed data.
const ( // CSV corresponds to lines of comma-separated values as described in RFC 4180. // See https://pkg.go.dev/encoding/csv. CSV Format = "csv" // KeyVal corresponds to an individual "field=value" pair on each line. // Unlike the other formats, this is used to specify a single edit. KeyVal Format = "keyval" // TSV corresponds to lines of tab-separated values. No escaping is supported. TSV Format = "tsv" )