fyp/main.go

66 lines
1.7 KiB
Go
Raw Normal View History

2023-09-18 00:26:42 +01:00
package main
import (
"database/sql"
"fmt"
2023-10-22 23:02:39 +01:00
"github.com/charmbracelet/log"
_ "github.com/lib/pq"
2023-10-20 11:03:07 +01:00
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models"
2024-04-12 20:36:23 +01:00
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks"
2023-10-20 11:03:07 +01:00
models_utils "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
2024-04-12 20:36:23 +01:00
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/runner"
)
const (
2024-01-31 21:48:35 +00:00
clear_db = false
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()
log.Info("Starting server on :5002!")
2023-09-18 00:26:42 +01:00
config := LoadConfig()
log.Info("Config loaded!", "config", config)
2024-04-12 20:36:23 +01:00
StartRunners(db, config)
2023-10-20 12:37:56 +01:00
//TODO check if file structure exists to save data
handle := NewHandler(db, config)
2023-09-18 00:26:42 +01:00
2024-01-31 21:48:35 +00:00
// TODO remove this before commiting
2023-10-20 12:37:56 +01:00
_, err = db.Exec("update models set status=$1 where status=$2", models_utils.FAILED_TRAINING, models_utils.TRAINING)
2024-01-31 21:48:35 +00:00
if err != nil && clear_db {
2023-10-22 23:02:39 +01:00
log.Warn("Database might not be on")
2023-10-20 12:37:56 +01:00
panic(err)
}
// TODO Handle this in other way
2023-10-20 12:37:56 +01:00
handle.StaticFiles("/styles/", ".css", "text/css")
handle.StaticFiles("/js/", ".js", "text/javascript")
handle.ReadFiles("/imgs/", "views", ".png", "image/png;")
handle.ReadTypesFiles("/savedData/", ".", []string{".png", ".jpeg"}, []string{"image/png", "image/jpeg"})
2024-03-02 12:45:49 +00:00
handle.ReadTypesFilesApi("/savedData/", ".", []string{".png", ".jpeg"}, []string{"image/png", "image/jpeg"})
2023-10-20 12:37:56 +01:00
usersEndpints(db, handle)
HandleModels(handle)
2024-04-12 20:36:23 +01:00
HandleTasks(handle)
2023-09-18 00:26:42 +01:00
handle.Startup()
2023-09-18 00:26:42 +01:00
}