Compare commits

..

2 Commits

Author SHA1 Message Date
Björn Busse aeb198e3c1 Rename timestamp function 2017-10-02 13:51:31 +00:00
Björn Busse e5040eeeac Add .gitignore 2017-10-02 13:50:18 +00:00
2 changed files with 13 additions and 13 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.swp
httptail

24
main.go
View File

@ -27,14 +27,13 @@ func fileHandler(w http.ResponseWriter, r *http.Request, s string) {
sendFile(w, fn, "", "No such file or directory") sendFile(w, fn, "", "No such file or directory")
return return
} }
fmt.Println("watch: %#v", watch)
if (watch == false) { if (watch == false) {
t, err := tail.TailFile(fn, tail.Config{Follow: false}) t, err := tail.TailFile(fn, tail.Config{Follow: false, MustExist: true})
watch = true watch = true
} if (err == nil) {
fmt.Println(err)
if (err == nil) { }
fmt.Println(err)
} }
var m = "" var m = ""
@ -52,10 +51,10 @@ func fileHandler(w http.ResponseWriter, r *http.Request, s string) {
} }
func sendFile(w http.ResponseWriter, fn string, m string, err string) { func sendFile(w http.ResponseWriter, fn string, m string, err string) {
json.NewEncoder(w).Encode(map[string]string{"time": strconv.FormatInt(t_ms(), 16), "Filename": fn, "Text": m, "error": err}) json.NewEncoder(w).Encode(map[string]string{"time": strconv.FormatInt(getMsTimestamp(), 16), "Filename": fn, "Text": m, "error": err})
} }
func t_ms() (int64) { func getMsTimestamp() (int64) {
now := time.Now() now := time.Now()
ns := now.UnixNano() ns := now.UnixNano()
ms := ns / 1000000 ms := ns / 1000000
@ -88,7 +87,6 @@ var m_prev = ""
func main() { func main() {
uid := os.Getuid() uid := os.Getuid()
t.Filename = ""
if (uid == -1) { if (uid == -1) {
fmt.Println("Windows is unsupported") fmt.Println("Windows is unsupported")
@ -101,7 +99,7 @@ func main() {
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()
} }