62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
"github.com/charmbracelet/log"
|
|
_ "github.com/lib/pq"
|
|
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models"
|
|
models_utils "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils"
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks"
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/runner"
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
|
)
|
|
|
|
const (
|
|
clear_db = false
|
|
host = "localhost"
|
|
port = 5432
|
|
user = "postgres"
|
|
password = "verysafepassword"
|
|
dbname = "aistuff"
|
|
)
|
|
|
|
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!")
|
|
|
|
config := LoadConfig()
|
|
log.Info("Config loaded!", "config", config)
|
|
|
|
StartRunners(db, config)
|
|
|
|
//TODO check if file structure exists to save data
|
|
handle := NewHandler(db, config)
|
|
|
|
// TODO remove this before commiting
|
|
_, err = db.Exec("update models set status=$1 where status=$2", models_utils.FAILED_TRAINING, models_utils.TRAINING)
|
|
if err != nil && clear_db {
|
|
log.Warn("Database might not be on")
|
|
panic(err)
|
|
}
|
|
|
|
// TODO Handle this in other way
|
|
handle.ReadTypesFilesApi("/savedData/", ".", []string{".png", ".jpeg"}, []string{"image/png", "image/jpeg"})
|
|
|
|
usersEndpints(db, handle)
|
|
HandleModels(handle)
|
|
HandleTasks(handle)
|
|
|
|
handle.Startup()
|
|
}
|