Files
MusicServer/internal/server/server.go
Sebastian 806e88adeb
All checks were successful
Build / build (push) Successful in 2m35s
#1 - Created request to check newest version of the app
#2 - Added request to download the newest version of the app
#3 - Added request to check progress during sync
#4 - Now blocking all request while sync is in progress
#5 - Implemented ants for thread pooling
#6 - Changed the sync request to now only start the sync
2025-08-23 11:36:03 +02:00

60 lines
1.3 KiB
Go

package server
import (
"fmt"
"log"
"music-server/internal/db"
"net/http"
"os"
"strconv"
"time"
)
type Server struct {
port int
}
var (
host = os.Getenv("DB_HOST")
dbPort = os.Getenv("DB_PORT")
dbName = os.Getenv("DB_NAME")
username = os.Getenv("DB_USERNAME")
password = os.Getenv("DB_PASSWORD")
musicPath = os.Getenv("MUSIC_PATH")
charactersPath = os.Getenv("CHARACTERS_PATH")
)
func NewServer() *http.Server {
port, _ := strconv.Atoi(os.Getenv("PORT"))
NewServer := &Server{
port: port,
}
fmt.Printf("host: %s, dbPort: %v, username: %s, password: %s, dbName: %s\n",
host, dbPort, username, password, dbName)
log.Printf("musicPath: %s\n", musicPath)
log.Printf("charactersPath: %s\n", charactersPath)
//conf.SetupDb()
if host == "" || dbPort == "" || username == "" || password == "" || dbName == "" || musicPath == "" || charactersPath == "" {
log.Fatal("Invalid settings")
}
db.Migrate_db(host, dbPort, username, password, dbName)
db.InitDB(host, dbPort, username, password, dbName)
// Declare Server config
server := &http.Server{
Addr: fmt.Sprintf(":%d", NewServer.port),
Handler: NewServer.RegisterRoutes(),
IdleTimeout: time.Minute,
ReadTimeout: 10 * time.Second,
WriteTimeout: 30 * time.Second,
}
return server
}