feat: use fmt.Sprintf to generate file paths

This commit is contained in:
Adrien Waksberg 2019-06-26 22:51:29 +02:00
parent 67c374d2e8
commit 06c2a76516
3 changed files with 8 additions and 3 deletions

View file

@ -11,6 +11,10 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
- A comment for all functions - A comment for all functions
### Changed
- Use fmt.Sprintf to generate file paths
### Removed ### Removed
- Duplicate array interval - Duplicate array interval

View file

@ -18,6 +18,7 @@
package main package main
import ( import (
"fmt"
"strings" "strings"
"regexp" "regexp"
"io/ioutil" "io/ioutil"
@ -43,7 +44,7 @@ func NewProc(pid int) *Proc {
// CmdLine return the command line for a process // CmdLine return the command line for a process
func CmdLine(pid int) string { func CmdLine(pid int) string {
data, err := ioutil.ReadFile("/proc/" + strconv.Itoa(pid) + "/cmdline") data, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
if err != nil { if err != nil {
return "" return ""
} }
@ -54,7 +55,7 @@ func CmdLine(pid int) string {
// Swap return the swap usage for a process // Swap return the swap usage for a process
func Swap(pid int) int { func Swap(pid int) int {
data, err := ioutil.ReadFile("/proc/" + strconv.Itoa(pid) + "/status") data, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/status", pid))
if err != nil { if err != nil {
return 0 return 0
} }

View file

@ -68,6 +68,6 @@ func main() {
if proc.Swap == 0 || proc.CmdLine == "" { if proc.Swap == 0 || proc.CmdLine == "" {
continue continue
} }
fmt.Printf("%d kB [%d] %v\n", proc.Swap, proc.Pid, proc.CmdLine) fmt.Printf("%d kB [%d] %s\n", proc.Swap, proc.Pid, proc.CmdLine)
} }
} }