package main import ( "context" "log" //"html/template" "net/http" "flag" "github.com/gorilla/websocket" "github.com/jackc/pgx/v5" ) type Message struct { Type string `json:"type"` Timestamp string `json:"timestamp"` Random float64 `json:"random"` } //var page_template = template.Must(template.ParseFiles("../../ui/html/index.html")) var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true }, // allow all origins } func main() { addr := flag.String("addr", ":8443", "HTTP network address") flag.Parse() conn, err := pgx.Connect(context.Background(), "postgres://party:iK2SoVbDhdCki5n3LxGyP6zKpLspt4@losandesgames.com:5432/party") if err != nil { log.Fatal(err) } defer conn.Close(context.Background()) database_init(conn) mux := http.NewServeMux() fileServer := http.FileServer(http.Dir("../../ui/static")) mux.HandleFunc("/", home) mux.HandleFunc("/ws", ws) mux.Handle("/static/", http.StripPrefix("/static", fileServer)) go func() { err := http.ListenAndServe(":8080", http.HandlerFunc(redirectToHTTPS)) if err != nil { panic(err) } }() log.Println("Starting server on", *addr) // Start HTTPS server (requires cert.pem and key.pem in current dir) err = http.ListenAndServeTLS(*addr, "cert.pem", "key.pem", mux) if err != nil { panic(err) } }