Skip to content

Commit

Permalink
Return {} instead of null in admin language stats API.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Nov 16, 2023
1 parent 36930f1 commit 7263d6f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (

// entry represents a single row read from the CSV. The CSV columns are:
// Array columns like tokens, tags etc. are pipe (|) separated.
// entry_type, word, initial, language, notes, tsvector_language, [tsvector_tokens], [tags], [phones], definition_type
// entry_type, word, initial, language, notes, tsvector_language, [tsvector_tokens], [tags], [phones], definition_type, meta
//
// entry_type = - represents a main entry and subsequent ^ represents definitions.
// definition_type (last field) should only be set in definition (^) entries.
Expand All @@ -45,6 +45,7 @@ type entry struct {
Tags []string // 7
Phones []string // 8
DefTypes []string // 9 - Only read in definition entries (0=^)
Meta string // 10

defs []entry
}
Expand Down Expand Up @@ -208,7 +209,14 @@ func (im *Importer) readEntry(r []string) (entry, error) {
}
e.DefTypes = defTypes
} else if defTypeStr != "" {
return e, fmt.Errorf("column 10, definition type (part of speec) should only be set of definition entries (^)")
return e, fmt.Errorf("column 10, definition type (part of speech) should only be set of definition entries (^)")
}

e.Meta = strings.TrimSpace(e.Meta)
if e.Meta[0:1] != "{" {
return e, fmt.Errorf("column 11, meta JSON should begin with `{`")
} else if e.Meta == "" {
e.Meta = "{}"
}

return e, nil
Expand Down

0 comments on commit 7263d6f

Please sign in to comment.