Browse Source

Refactor: move encoder and writer out of the loop

No need to redefine these variables.
Oz Tiram 5 years ago
parent
commit
d5d8d40a65
1 changed files with 3 additions and 2 deletions
  1. 3 2
      cmd/main.go

+ 3 - 2
cmd/main.go

@@ -31,6 +31,9 @@ func main() {
 	var partition, netInterface string
 	var load, memory, cpu bool
 
+	writer := os.Stdout
+	enc := json.NewEncoder(writer)
+
 	flag.IntVar(&interval, "i", 5, "polling inteval")
 	flag.BoolVar(&memory, "m", false, "Poll memory")
 	flag.BoolVar(&load, "l", false, "Poll load")
@@ -63,8 +66,6 @@ func main() {
 			mem := gupta.NewMemory(m)
 			report.MemoryUsage = &mem
 		}
-		writer := os.Stdout
-		enc := json.NewEncoder(writer)
 		if err := enc.Encode(&report); err != nil {
 			log.Println(err)
 		}