Reorganized the code, moved more things to the new part

This commit is contained in:
2025-01-13 16:08:54 +01:00
parent 034ba35fbb
commit 5b640375c3
38 changed files with 213 additions and 2028 deletions

View File

@@ -2,7 +2,8 @@ package server
import (
"fmt"
"music-server/pkg/conf"
"log"
"music-server/pkg/db"
"net/http"
"os"
"strconv"
@@ -13,6 +14,15 @@ type Server struct {
port int
}
var (
host = os.Getenv("DB_HOST")
dbPort = os.Getenv("DB_PORT")
database = os.Getenv("DB_NAME")
username = os.Getenv("DB_USERNAME")
password = os.Getenv("DB_PASSWORD")
musicPath = os.Getenv("MUSIC_PATH")
)
func NewServer() *http.Server {
port, _ := strconv.Atoi(os.Getenv("PORT"))
@@ -20,7 +30,19 @@ func NewServer() *http.Server {
port: port,
}
conf.SetupDb()
//conf.SetupDb()
if host == "" || dbPort == "" || username == "" || password == "" || database == "" || musicPath == "" {
log.Fatal("Invalid settings")
}
fmt.Printf("host: %s, dbPort: %v, username: %s, password: %s, dbName: %s\n",
host, dbPort, username, password, database)
log.Printf("Path: %s\n", musicPath)
db.Migrate_db(host, dbPort, username, password, database)
db.InitDB(host, dbPort, username, password, database)
// Declare Server config
server := &http.Server{