diff --git a/main.go b/main.go index 4f432e3..fccacf5 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,16 @@ package main import ( - "container/ring" - "fmt" - "github.com/hpcloud/tail" - "encoding/json" - "net/http" - "os" - "regexp" - "strconv" - "strings" - "time" + "container/ring" + "fmt" + "github.com/hpcloud/tail" + "encoding/json" + "net/http" + "os" + "regexp" + "strconv" + "strings" + "time" ) func fileHandler(w http.ResponseWriter, r *http.Request, s string) { @@ -19,7 +19,7 @@ func fileHandler(w http.ResponseWriter, r *http.Request, s string) { for _, v := range whitelist { if !strings.Contains(v, fn) { sendFile(w, fn, "", "Permission denied") - return + return } } @@ -30,7 +30,7 @@ func fileHandler(w http.ResponseWriter, r *http.Request, s string) { if (watch == false) { t, err := tail.TailFile(fn, tail.Config{Follow: false}) - watch = true + watch = true } if (err == nil) { @@ -78,7 +78,7 @@ var prj = "httptail" var version = "0.1.0" var server_inet6 = "[fdef:c181:4234:7978:6::1]:8080" var whitelist = map[int]string{ - 0: "/var/log", + 0: "/var/log", } var logring = ring.New(1000) @@ -87,21 +87,21 @@ var watch bool = false var m_prev = "" func main() { - uid := os.Getuid() - t.Filename = "" + uid := os.Getuid() + t.Filename = "" - if (uid == -1) { - fmt.Println("Windows is unsupported") + if (uid == -1) { + fmt.Println("Windows is unsupported") } - if (uid == 0) { + if (uid == 0) { fmt.Println("Refusing to run as root") - return - } + return + } - http.HandleFunc("/tail/", makeHandler(fileHandler)) + http.HandleFunc("/tail/", makeHandler(fileHandler)) fmt.Println("Serving " + prj + " " + version + " on " + server_inet6) http.ListenAndServe(server_inet6, nil) - t.Cleanup() + t.Cleanup() }