62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"lostcavewireplanner/internal/db"
|
|
"lostcavewireplanner/internal/handlers"
|
|
)
|
|
|
|
func main() {
|
|
database, err := db.Init("data.db")
|
|
if err != nil {
|
|
log.Fatalf("failed to init database: %v", err)
|
|
}
|
|
defer database.Close()
|
|
|
|
h := handlers.New(database)
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
fsStatic := http.FileServer(http.Dir("static"))
|
|
mux.Handle("GET /static/", http.StripPrefix("/static/", fsStatic))
|
|
|
|
fsUploads := http.FileServer(http.Dir("uploads"))
|
|
mux.Handle("GET /uploads/", http.StripPrefix("/uploads/", fsUploads))
|
|
|
|
mux.HandleFunc("GET /{$}", h.Overview)
|
|
mux.HandleFunc("POST /racks/add", h.RackCreate)
|
|
mux.HandleFunc("GET /racks/{id}", h.RackView)
|
|
mux.HandleFunc("POST /racks/{id}/delete", h.RackDelete)
|
|
mux.HandleFunc("POST /racks/{id}/edit", h.RackEdit)
|
|
mux.HandleFunc("POST /racks/{id}/devices/add/racked", h.RackAddRackedDevice)
|
|
mux.HandleFunc("POST /racks/{id}/devices/add/unracked", h.RackAddUnrackedDevice)
|
|
mux.HandleFunc("POST /racks/{id}/devices/{devId}/remove", h.RackRemoveDevice)
|
|
mux.HandleFunc("POST /devices/{id}/edit", h.DeviceEdit)
|
|
mux.HandleFunc("POST /devices/{id}/delete", h.DeviceDelete)
|
|
mux.HandleFunc("POST /devices/add", h.DeviceCreate)
|
|
mux.HandleFunc("GET /devices/{id}", h.DeviceView)
|
|
mux.HandleFunc("GET /models", h.ModelList)
|
|
mux.HandleFunc("GET /models/new", h.ModelCreateForm)
|
|
mux.HandleFunc("POST /models/create", h.ModelCreate)
|
|
mux.HandleFunc("GET /models/{id}/edit", h.ModelEditForm)
|
|
mux.HandleFunc("POST /models/{id}/update", h.ModelUpdate)
|
|
mux.HandleFunc("POST /models/{id}/delete", h.ModelDelete)
|
|
mux.HandleFunc("GET /connections/{portId}", h.ConnectionModal)
|
|
mux.HandleFunc("POST /connections/create", h.ConnectionCreate)
|
|
mux.HandleFunc("POST /connections/{id}/edit", h.ConnectionEdit)
|
|
mux.HandleFunc("POST /connections/{id}/delete", h.ConnectionDelete)
|
|
mux.HandleFunc("GET /wall-sockets", h.WallSockets)
|
|
mux.HandleFunc("POST /wall-sockets/add", h.WallSocketCreate)
|
|
mux.HandleFunc("POST /wall-sockets/{id}/delete", h.WallSocketDelete)
|
|
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
}
|
|
log.Printf("Listening on :%s", port)
|
|
log.Fatal(http.ListenAndServe(":"+port, mux))
|
|
}
|