Whitespace fixes

This commit is contained in:
Björn Busse 2017-10-02 10:54:27 +00:00
parent 9ae20db92e
commit 3b3f68c525

44
main.go
View File

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