Files
signoz/pkg/units/formatter_bool.go
Srikanth Chekuri 43933f3a33
Some checks failed
build-staging / prepare (push) Has been cancelled
build-staging / js-build (push) Has been cancelled
build-staging / go-build (push) Has been cancelled
build-staging / staging (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
chore: move converter/formatter to pkg/units/... (#10408)
2026-02-26 23:52:58 +05:30

50 lines
768 B
Go

package units
import "fmt"
type boolFormatter struct{}
func NewBoolFormatter() Formatter {
return &boolFormatter{}
}
func (*boolFormatter) Name() string {
return "bool"
}
func toBool(value float64) string {
if value == 0 {
return "false"
}
return "true"
}
func toBoolYesNo(value float64) string {
if value == 0 {
return "no"
}
return "yes"
}
func toBoolOnOff(value float64) string {
if value == 0 {
return "off"
}
return "on"
}
func (f *boolFormatter) Format(value float64, unit string) string {
switch unit {
case "bool":
return toBool(value)
case "bool_yes_no":
return toBoolYesNo(value)
case "bool_on_off":
return toBoolOnOff(value)
}
// When unit is not matched, return the value as it is.
return fmt.Sprintf("%v", value)
}