summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Gamsjager <matthias.gamsjager@philips.com>2019-05-14 12:43:39 +0200
committerMatthias Gamsjager <matthias.gamsjager@philips.com>2019-05-14 13:00:04 +0200
commitea5e097d52c5d1ffa832248e0eb04f6aa649164e (patch)
treed42e75458215ce70ddf48b6300bcb6b0ec8b2f24
parent68d38a61d7ce0a854c604a698f917a3b80b2c9b4 (diff)
Proper json helper
-rw-r--r--src/widgets/proc_freebsd.go28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/widgets/proc_freebsd.go b/src/widgets/proc_freebsd.go
index 0122496..96c8833 100644
--- a/src/widgets/proc_freebsd.go
+++ b/src/widgets/proc_freebsd.go
@@ -11,16 +11,16 @@ import (
"strings"
)
-type Keywords struct {
+type processList struct {
ProcessInformation struct {
Process []struct {
- Pid string `json: pid`
- Comm string `json: command`
- Cpu string `json: percent-cpu`
- Mem string `json: percent-memory`
- Args string `json: arguments`
- } `json: process`
- } `json: process-information`
+ Pid string `json:"pid"`
+ Comm string `json:"command"`
+ Cpu string `json:"percent-cpu" `
+ Mem string `json:"percent-memory" `
+ Args string `json:"arguments" `
+ } `json:"process"`
+ } `json:"process-information"`
}
func getProcs() ([]Proc, error) {
@@ -29,17 +29,17 @@ func getProcs() ([]Proc, error) {
return nil, fmt.Errorf("failed to execute 'ps' command: %v", err)
}
- processList := Keywords{}
- err = json.Unmarshal(output, &processList)
+ list := processList{}
+ err = json.Unmarshal(output, &list)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal json. %s", err)
- } else {
- return nil, fmt.Errorf("Success to unmarshal json. %s", output)
}
-
procs := []Proc{}
- for _, process := range processList.ProcessInformation.Process {
+ for _, process := range list.ProcessInformation.Process {
+ if process.Comm == "idle" {
+ continue
+ }
pid, err := strconv.Atoi(strings.TrimSpace(process.Pid))
if err != nil {
log.Printf("failed to convert first field to int: %v. split: %v", err, process)