-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (29 loc) · 848 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
39
package main
import (
"devicify/backend/api"
"devicify/backend/database"
"html/template"
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
database.InitDB()
r := mux.NewRouter()
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("frontend/static"))))
r.HandleFunc("/", landingPageHandler)
r.HandleFunc("/api/device/{id}/users", api.GetDeviceUsers).Methods("GET")
log.Println("Server starting on :8080")
log.Fatal(http.ListenAndServe(":8080", r))
}
func landingPageHandler(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.ParseFiles("frontend/templates/index.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = tmpl.Execute(w, nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}