-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (33 loc) · 897 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"github.com/dustin-ward/minecraft-time-logging/parser"
"github.com/dustin-ward/minecraft-time-logging/routes"
"github.com/dustin-ward/minecraft-time-logging/util"
"github.com/gorilla/mux"
)
func main() {
// Parse each log file in /logs/
dir, _ := os.Getwd()
err := filepath.Walk(dir+"/logs/", func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
if filepath.Ext(path) == ".log" {
parser.Parse(path)
}
return nil
})
util.ErrorCheck(err)
// Setup HTTP router
r := mux.NewRouter()
r.HandleFunc("/", routes.HomePage)
r.HandleFunc("/user/{username}", routes.UserPage)
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./public"))))
fmt.Println("Page running on localhost:8080")
log.Fatal(http.ListenAndServe(":8080", r))
}