fixed issues with first-time setup, added config.db.port

This commit is contained in:
ari melody 2025-01-21 14:12:21 +00:00
parent 7bea6b548e
commit 3d674515ce
Signed by: ari
GPG key ID: CF99829C92678188
4 changed files with 26 additions and 12 deletions

11
main.go
View file

@ -30,6 +30,10 @@ const DEFAULT_PORT int64 = 8080
func main() {
fmt.Printf("made with <3 by ari melody\n\n")
// TODO: refactor `global` to `AppState`
// this should contain `Config` and `DB`, and be passed through to all
// handlers that need it. it's better than weird static globals everywhere!
// initialise database connection
if global.Config.DB.Host == "" {
fmt.Fprintf(os.Stderr, "FATAL: db.host not provided! Exiting...\n")
@ -52,8 +56,9 @@ func main() {
global.DB, err = sqlx.Connect(
"postgres",
fmt.Sprintf(
"host=%s user=%s dbname=%s password='%s' sslmode=disable",
"host=%s port=%d user=%s dbname=%s password='%s' sslmode=disable",
global.Config.DB.Host,
global.Config.DB.Port,
global.Config.DB.User,
global.Config.DB.Name,
global.Config.DB.Pass,
@ -319,7 +324,7 @@ func main() {
os.Exit(1)
}
fmt.Fprintf(os.Stdout, "No accounts exist! Generated invite code: " + string(invite.Code) + "\nUse this at %s/admin/register.\n", global.Config.BaseUrl)
fmt.Printf("No accounts exist! Generated invite code: %s\n", invite.Code)
}
// delete expired invites
@ -331,7 +336,7 @@ func main() {
// start the web server!
mux := createServeMux()
fmt.Printf("Now serving at http://127.0.0.1:%d\n", global.Config.Port)
fmt.Printf("Now serving at %s:%d\n", global.Config.BaseUrl, global.Config.Port)
log.Fatal(
http.ListenAndServe(fmt.Sprintf(":%d", global.Config.Port),
global.HTTPLog(global.DefaultHeaders(mux)),