court/main.go

31 lines
695 B
Go
Raw Normal View History

2024-03-27 18:13:05 +01:00
package main
2024-03-28 11:29:32 +01:00
import (
"court/handlers"
"court/utils"
"fmt"
"log"
"net/http"
)
2024-03-27 18:13:05 +01:00
func main() {
2024-03-28 11:29:32 +01:00
port := utils.Getenv("COURT_PORT", "8080")
address := utils.Getenv("COURT_ADDR", "0.0.0.0")
handlers.BaseURL = utils.Getenv("COURT_URL", "https://court.local/")
err := handlers.SetupDB()
if err != nil {
log.Panic(err)
}
defer handlers.DB.Close()
http.HandleFunc("GET /webui", handlers.Webui)
http.HandleFunc("GET /{id}", handlers.Redirect)
http.HandleFunc("DELETE /{id}", handlers.Delete)
http.HandleFunc("POST /", handlers.Post)
listen_addr := fmt.Sprintf("%s:%s", address, port)
fmt.Printf("\nListening on address: %s\n", listen_addr)
http.ListenAndServe(listen_addr, nil)
2024-03-27 18:13:05 +01:00
}