pgsql
This commit is contained in:
1 parent
b262e2d8ed
commit
d88952fa70
3 files changed
+119
-9
No files matched your search
+88
-2
@@ -1,13 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
//"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
@@ -85,7 +89,87 @@ func redirect_to_HTTPS(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "https://localhost:8443" + r.URL.RequestURI(), http.StatusMovedPermanently)
|
||||
}
|
||||
|
||||
func database_init(conn *pgx.Conn) {
|
||||
sql := "DROP TABLE IF EXISTS account"
|
||||
|
||||
_, err := conn.Exec(context.Background(), sql)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
sql = `CREATE TABLE account (
|
||||
id bigserial primary KEY,
|
||||
username varchar(20) NOT NULL,
|
||||
password text NOT NULL,
|
||||
firstname varchar(255) NOT NULL,
|
||||
lastname varchar(255) NOT NULL,
|
||||
email varchar(255) NOT NULL,
|
||||
created timestamptz DEFAULT now() NOT NULL,
|
||||
CONSTRAINT accounts_uc_email UNIQUE (email),
|
||||
CONSTRAINT accounts_username_key UNIQUE (username))`
|
||||
|
||||
_, err = conn.Exec(context.Background(), sql)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
sql = `INSERT INTO account
|
||||
(id, username, "password", firstname, lastname, email, created)
|
||||
VALUES(25, 'vik', '$argon2id$v=19$m=65536,t=1,p=32$+dQ9uB7kKL7t7G3bI+TOMw$Wvic27W6SYH6Fx2Pp84irhVJ/blVh5qINlkv58bpgEc', 'Vicente', 'Ferrari Smith', 'vikhenzo@gmail.com', '2024-05-24 13:21:48.179');
|
||||
|
||||
INSERT INTO account
|
||||
(id, username, "password", firstname, lastname, email, created)
|
||||
VALUES(26, 'Al Orjales', '$argon2id$v=19$m=65536,t=1,p=1$rQODKJ0+mUZ6v6ChUAcr4Q$x0cDjym/QB9lFFq/77FPv7R90Ao5gldb9cuNprBpGAs', '', '', '', '2024-09-26 17:43:37.879');
|
||||
|
||||
INSERT INTO account
|
||||
(id, username, "password", firstname, lastname, email, created)
|
||||
VALUES(36, 'mkBflwkpe', '$argon2id$v=19$m=65536,t=1,p=1$BWcWdp8bhgS84LWqUCb2IA$DGF/FzQbSNHnfZraE9F2qvfdBGf5XB81+w00QgY/jG0', 'zWkxKTNolTgJwO', 'OahedOBLSo', 'bellrebekaou@gmail.com', '2024-11-25 03:00:18.211');
|
||||
|
||||
INSERT INTO account
|
||||
(id, username, "password", firstname, lastname, email, created)
|
||||
VALUES(29, 'TzBeIMeRjxrfsM', '$argon2id$v=19$m=65536,t=1,p=1$ZIpNaO6RPeGncWe9cw8Iog$di0qjf8G0HlcZE8Hl+krNDlBeMrtfuGMwFWAlAnEMNs', 'ZBbLOWXqQlr', 'pIomimIQ', 'denielkgb21@gmail.com', '2024-11-19 13:20:33.177');
|
||||
|
||||
INSERT INTO account
|
||||
(id, username, "password", firstname, lastname, email, created)
|
||||
VALUES(38, 'TeAOvwIdnfqpxy', '$argon2id$v=19$m=65536,t=1,p=1$GRL555iybL1S8GjPq8jlOg$YnuwBxHAT8/I+cU548CYuhwaJdcEXe+R2PQbYpV7UKQ', 'RzqsaECTYrz', 'zreWiEtZGOeRNI', 'aolelonnum@yahoo.com', '2024-11-26 01:19:37.780');
|
||||
|
||||
INSERT INTO account
|
||||
(id, username, "password", firstname, lastname, email, created)
|
||||
VALUES(32, 'XIdQMFvxmT', '$argon2id$v=19$m=65536,t=1,p=1$PIcX7GObR0wlgRTmcMRUug$Kpc7SAv5K1PRxBtqioV4uoCZlkvGebkBmYyXCwoTgmM', 'ayZKALohBYmBx', 'smILWvtOvb', 'heilwoodsf@gmail.com', '2024-11-23 00:41:59.471');
|
||||
|
||||
INSERT INTO account
|
||||
(id, username, "password", firstname, lastname, email, created)
|
||||
VALUES(34, 'yIQvINFS', '$argon2id$v=19$m=65536,t=1,p=1$SJxMxkotEr+lfGeaCs7vlA$fffslijaMuPy+XPBEdv9iPqLbt66H/qJbGUHGrbpdz0', 'nKXBOwRbtXmMedo', 'KvMechDKtPPMgM', 'cortezzavira@gmail.com', '2024-11-24 06:29:58.378');
|
||||
|
||||
INSERT INTO account
|
||||
(id, username, "password", firstname, lastname, email, created)
|
||||
VALUES(40, 'HEjcEByjlPjtaGE', '$argon2id$v=19$m=65536,t=1,p=1$Hu2qnPxi0nz0OHx97h5j5Q$xh7HwKBIi9mp+WWU7rS9MfnDohtJqrv0EUrF2mVpnto', 'yJrQikhSHRYNgdu', 'GttOfPxSPoVWWl', 'jacobsheizitn4963@gmail.com', '2024-11-27 00:07:53.617');
|
||||
|
||||
INSERT INTO account
|
||||
(id, username, "password", firstname, lastname, email, created)
|
||||
VALUES(42, 'DggewDRjXu', '$argon2id$v=19$m=65536,t=1,p=1$MzFSqUr5J5IRC930empHrw$y7kogPP715NOtazsXqjR56LQGF2Eaes9CyAoPjRm3xk', 'uMezBkaQcfBbD', 'YoaQNBvZgHvTaFf', 'kinharrispa@gmail.com', '2024-11-27 21:55:53.037');
|
||||
|
||||
INSERT INTO account
|
||||
(id, username, "password", firstname, lastname, email, created)
|
||||
VALUES(44, 'yyZGFAsmPEBoSf', '$argon2id$v=19$m=65536,t=1,p=1$vLVm5ol6GQkXPU0BPut92g$Kyvp7/dl3lGUszXRiXfgsgB/IY0EKulZVpVttXQaDDU', 'svVjyPUaAkN', 'mdngeHlf', 'giyahyd4141@gmail.com', '2024-11-28 19:02:32.806');`
|
||||
|
||||
_, err = conn.Exec(context.Background(), sql)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
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)
|
||||
|
||||
http.HandleFunc("/", handler)
|
||||
http.HandleFunc("/ws", ws_handler)
|
||||
|
||||
@@ -96,8 +180,10 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
log.Println("Starting server on :8443")
|
||||
|
||||
// Start HTTPS server (requires cert.pem and key.pem in current dir)
|
||||
err := http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", nil)
|
||||
err = http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user