Browse files

gofmt

  • Loading branch information...
1 parent 0acd45f commit c6a59141845f24054619c2c665ef073a1ffdbdd1 @cdarwin committed Jul 3, 2012
Showing with 56 additions and 56 deletions.
  1. +56 −56 simple_statusd.go
View
112 simple_statusd.go
@@ -1,86 +1,86 @@
package main
import (
- "bufio"
- "bytes"
- "encoding/json"
- "fmt"
- "io"
- "io/ioutil"
- "net/http"
- "os"
- "time"
+ "bufio"
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "time"
)
type Message struct {
- Host string
- Load string
- Rams string
- Time string
+ Host string
+ Load string
+ Rams string
+ Time string
}
func host() string {
- host, err := os.Hostname()
- if err != nil {
- return fmt.Sprint(err)
- }
- return host
+ host, err := os.Hostname()
+ if err != nil {
+ return fmt.Sprint(err)
+ }
+ return host
}
func load() string {
- b, err := ioutil.ReadFile("/proc/loadavg")
- if err != nil {
- return fmt.Sprint(err)
- }
- return fmt.Sprintf("%s", b[:len(b)-1])
+ b, err := ioutil.ReadFile("/proc/loadavg")
+ if err != nil {
+ return fmt.Sprint(err)
+ }
+ return fmt.Sprintf("%s", b[:len(b)-1])
}
func ram() string {
- f, err := os.Open("/proc/meminfo")
- if err != nil {
- return fmt.Sprint(err)
- }
- defer f.Close()
+ f, err := os.Open("/proc/meminfo")
+ if err != nil {
+ return fmt.Sprint(err)
+ }
+ defer f.Close()
- bufReader := bufio.NewReader(f)
- b := make([]byte, 100)
- var free, total string
- for line, isPrefix, err := bufReader.ReadLine(); err != io.EOF; line, isPrefix, err = bufReader.ReadLine() {
- b = append(b, line...)
+ bufReader := bufio.NewReader(f)
+ b := make([]byte, 100)
+ var free, total string
+ for line, isPrefix, err := bufReader.ReadLine(); err != io.EOF; line, isPrefix, err = bufReader.ReadLine() {
+ b = append(b, line...)
- if !isPrefix {
- switch {
- case bytes.Contains(b, []byte("MemFree")):
- s := bytes.Fields(b)
- free = string(s[1])
- case bytes.Contains(b, []byte("MemTotal")):
- s := bytes.Fields(b)
- total = string(s[1])
- }
- b = b[:0]
- }
- }
- return fmt.Sprintf("%s/%s", free, total)
+ if !isPrefix {
+ switch {
+ case bytes.Contains(b, []byte("MemFree")):
+ s := bytes.Fields(b)
+ free = string(s[1])
+ case bytes.Contains(b, []byte("MemTotal")):
+ s := bytes.Fields(b)
+ total = string(s[1])
+ }
+ b = b[:0]
+ }
+ }
+ return fmt.Sprintf("%s/%s", free, total)
}
func now() string {
- return time.Now().Format("2006 01/02 1504-05")
+ return time.Now().Format("2006 01/02 1504-05")
}
func message() []byte {
- m := Message{host(), load(), ram(), now()}
- b, err := json.Marshal(m)
- if err != nil {
- return nil
- }
- return b
+ m := Message{host(), load(), ram(), now()}
+ b, err := json.Marshal(m)
+ if err != nil {
+ return nil
+ }
+ return b
}
func handler(w http.ResponseWriter, r *http.Request) {
- fmt.Fprintf(w, "%s", message())
+ fmt.Fprintf(w, "%s", message())
}
func main() {
- http.HandleFunc("/", handler)
- http.ListenAndServe(":8080", nil)
+ http.HandleFunc("/", handler)
+ http.ListenAndServe(":8080", nil)
}

0 comments on commit c6a5914

Please sign in to comment.