2023-09-18 00:26:42 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-09-19 13:39:59 +01:00
|
|
|
"database/sql"
|
2023-09-21 15:38:02 +01:00
|
|
|
"fmt"
|
2023-09-19 13:39:59 +01:00
|
|
|
|
|
|
|
_ "github.com/lib/pq"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
host = "localhost"
|
|
|
|
port = 5432
|
|
|
|
user = "postgres"
|
|
|
|
password = "verysafepassword"
|
|
|
|
dbname = "aistuff"
|
2023-09-18 00:26:42 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-09-19 13:39:59 +01:00
|
|
|
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+
|
|
|
|
"password=%s dbname=%s sslmode=disable",
|
|
|
|
host, port, user, password, dbname)
|
|
|
|
|
|
|
|
db, err := sql.Open("postgres", psqlInfo)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer db.Close()
|
2023-09-18 00:26:42 +01:00
|
|
|
fmt.Println("Starting server on :8000!")
|
|
|
|
|
2023-09-21 15:38:02 +01:00
|
|
|
//TODO check if file structure exists to save data
|
|
|
|
|
2023-09-19 13:39:59 +01:00
|
|
|
handle := NewHandler(db)
|
2023-09-18 00:26:42 +01:00
|
|
|
|
2023-09-21 15:38:02 +01:00
|
|
|
|
|
|
|
// TODO Handle this in other way
|
|
|
|
handle.staticFiles("/styles/", ".css", "text/css");
|
|
|
|
handle.staticFiles("/js/", ".js", "text/javascript");
|
|
|
|
handle.readFiles("/imgs/", "views", ".png", "image/png;");
|
|
|
|
handle.readFiles("/savedData/", ".", ".png", "image/png;");
|
|
|
|
|
|
|
|
handle.GetHTML("/", AnswerTemplate("index.html", nil, 0))
|
2023-09-19 13:39:59 +01:00
|
|
|
|
|
|
|
usersEndpints(db, handle)
|
2023-09-21 15:38:02 +01:00
|
|
|
handleModelsEndpoints(handle)
|
2023-09-18 00:26:42 +01:00
|
|
|
|
2023-09-18 13:50:03 +01:00
|
|
|
handle.Startup()
|
2023-09-18 00:26:42 +01:00
|
|
|
}
|