fyp/main.go

51 lines
1.1 KiB
Go
Raw Normal View History

2023-09-18 00:26:42 +01:00
package main
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models"
)
const (
host = "localhost"
port = 5432
user = "postgres"
password = "verysafepassword"
dbname = "aistuff"
2023-09-18 00:26:42 +01:00
)
func main() {
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!")
//TODO check if file structure exists to save data
handle := NewHandler(db)
2023-09-18 00:26:42 +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))
usersEndpints(db, handle)
HandleModels(handle)
2023-09-18 00:26:42 +01:00
handle.Startup()
2023-09-18 00:26:42 +01:00
}