From 6907f598f8374d4691579943c48bec01de274401 Mon Sep 17 00:00:00 2001 From: Matthias Gamsjager Date: Tue, 28 May 2019 11:42:40 -0700 Subject: [PATCH] Fix process localization issues on FreeBSD --- src/utils/conversions.go | 13 +++++++++++++ src/widgets/proc_freebsd.go | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 src/utils/conversions.go diff --git a/src/utils/conversions.go b/src/utils/conversions.go new file mode 100644 index 0000000..5d86ac4 --- /dev/null +++ b/src/utils/conversions.go @@ -0,0 +1,13 @@ +package utils + +import ( + "strings" +) + +func ConvertLocalizedString(s string) string { + if strings.ContainsAny(s, ",") { + return strings.Replace(s, ",", ".", 1) + } else { + return s + } +} diff --git a/src/widgets/proc_freebsd.go b/src/widgets/proc_freebsd.go index 96c8833..dc4399b 100644 --- a/src/widgets/proc_freebsd.go +++ b/src/widgets/proc_freebsd.go @@ -1,5 +1,3 @@ -// +build freebsd - package widgets import ( @@ -9,6 +7,8 @@ import ( "os/exec" "strconv" "strings" + + "github.com/cjbassi/gotop/src/utils" ) type processList struct { @@ -44,11 +44,11 @@ func getProcs() ([]Proc, error) { if err != nil { log.Printf("failed to convert first field to int: %v. split: %v", err, process) } - cpu, err := strconv.ParseFloat(process.Cpu, 64) + cpu, err := strconv.ParseFloat(utils.ConvertLocalizedString(process.Cpu), 32) if err != nil { log.Printf("failed to convert third field to float: %v. split: %v", err, process) } - mem, err := strconv.ParseFloat(process.Mem, 64) + mem, err := strconv.ParseFloat(utils.ConvertLocalizedString(process.Mem), 32) if err != nil { log.Printf("failed to convert fourth field to float: %v. split: %v", err, process) }