Images should not be included in the database Removes songs where the path doesn't work Started working on adding cover images Started adding vue directly in the application
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package conf
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gorilla/mux"
|
|
"log"
|
|
"music-server/pkg/api"
|
|
"music-server/pkg/db"
|
|
"net/http"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
func SetupDb() {
|
|
// Get the value of an Environment Variable
|
|
host := os.Getenv("DB_HOST")
|
|
dbPort, dbPortErr := strconv.Atoi(os.Getenv("DB_PORT"))
|
|
if dbPortErr != nil {
|
|
dbPort = 0
|
|
}
|
|
username := os.Getenv("DB_USERNAME")
|
|
password := os.Getenv("DB_PASSWORD")
|
|
dbName := os.Getenv("DB_NAME")
|
|
|
|
fmt.Printf("host: %s, dbPort: %v, username: %s, password: %s, dbName: %s\n",
|
|
host, dbPort, username, password, dbName)
|
|
|
|
if host == "" {
|
|
host = "localhost"
|
|
}
|
|
if dbPort == 0 {
|
|
dbPort = 5432
|
|
}
|
|
if username == "" {
|
|
username = "sebastian"
|
|
}
|
|
if password == "" {
|
|
password = "950100"
|
|
}
|
|
if dbName == "" {
|
|
dbName = "music_dev_local"
|
|
}
|
|
|
|
db.InitDB(host, dbPort, username, password, dbName)
|
|
}
|
|
|
|
func CloseDb() {
|
|
defer db.CloseDb()
|
|
}
|
|
|
|
func SetupRestServer() {
|
|
r := mux.NewRouter()
|
|
r.HandleFunc("/sync", api.SyncHandler)
|
|
r.HandleFunc("/sync/{func}", api.SyncHandler)
|
|
r.HandleFunc("/music", api.MusicHandler)
|
|
r.HandleFunc("/music/{func}", api.MusicHandler)
|
|
r.HandleFunc("/music/{func}/{func2}", api.MusicHandler)
|
|
r.HandleFunc("/{func}", api.IndexHandler)
|
|
r.Handle("/", http.FileServer(http.FS(os.DirFS("frontend/dist"))))
|
|
http.Handle("/", r)
|
|
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
log.Printf("Defaulting to port %s", port)
|
|
}
|
|
|
|
log.Printf("Listening on port %s", port)
|
|
log.Printf("Open http://localhost:%s in the browser", port)
|
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
|
|
}
|