Skip to content

Commit

Permalink
(#3) Improve nil number rendering
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed Aug 5, 2022
1 parent 11417b6 commit a61b310
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
12 changes: 6 additions & 6 deletions formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (f *formatter) getDataItem(data json.RawMessage, item string) (gjson.Result

func formatDataItem(val gjson.Result, format string) (string, error) {
if !val.Exists() || val.Type == gjson.Null {
return strings.Repeat(" ", len(format)), nil
return "?" + strings.Repeat(" ", len(format)-1), nil
}

switch val.Type {
Expand Down Expand Up @@ -179,15 +179,15 @@ func formatCommaNumber(v any, format string) (string, error) {
case float32:
return humanize.Commaf(float64(nv)), nil
case int:
return humanize.Commaf(float64(nv)), nil
return humanize.Comma(int64(nv)), nil
case int8:
return humanize.Commaf(float64(nv)), nil
return humanize.Comma(int64(nv)), nil
case int16:
return humanize.Commaf(float64(nv)), nil
return humanize.Comma(int64(nv)), nil
case int32:
return humanize.Commaf(float64(nv)), nil
return humanize.Comma(int64(nv)), nil
case int64:
return humanize.Commaf(float64(nv)), nil
return humanize.Comma(int64(nv)), nil
default:
return "", fmt.Errorf("do not know how to handle value %v", v)
}
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ module github.com/choria-io/goform
go 1.18

require (
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/tidwall/gjson v1.14.1 // indirect
github.com/dustin/go-humanize v1.0.0
github.com/tidwall/gjson v1.14.2
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.2 h1:6BBkirS0rAHjumnjHF6qgy5d2YAJ1TLIaFE2lzfOLqo=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion report.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
type Report struct {
Name string `json:"name" yaml:"name"`
BodyLayout string `json:"body" yaml:"body"`
HeaderLayout string `json:"header" yaml:"heqder"`
HeaderLayout string `json:"header" yaml:"header"`
FooterLayout string `json:"footer" yaml:"footer"`
RowsPerPage int `json:"rows_per_page" yaml:"rows_per_page"`
bodyLines []string
Expand Down

0 comments on commit a61b310

Please sign in to comment.