mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-22 00:21:55 +00:00
Add MBID
Add ability to set custom port
This commit is contained in:
parent
a22f282a6d
commit
08f0cb6c80
@ -6,4 +6,5 @@ MYSQL_DB=
|
||||
JWT_SECRET=
|
||||
JWT_EXPIRY=86400
|
||||
|
||||
REVERSE_PROXIES=127.0.0.1
|
||||
REVERSE_PROXIES=127.0.0.1
|
||||
PORT=42069
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -12,6 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Starting goscrobble")
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
@ -35,10 +37,16 @@ func main() {
|
||||
// Ignore reverse proxies
|
||||
goscrobble.ReverseProxies = strings.Split(os.Getenv("REVERSE_PROXIES"), ",")
|
||||
|
||||
// // Boot up DB connection for life of application
|
||||
// Store port
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "42069"
|
||||
}
|
||||
|
||||
// Boot up DB connection for life of application
|
||||
goscrobble.InitDb()
|
||||
defer goscrobble.CloseDbConn()
|
||||
|
||||
// Boot up API webserver \o/
|
||||
goscrobble.HandleRequests()
|
||||
goscrobble.HandleRequests(port)
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ func CloseDbConn() {
|
||||
}
|
||||
|
||||
func runMigrations() {
|
||||
fmt.Println("Checking database migrations")
|
||||
driver, err := mysql.WithInstance(db, &mysql.Config{})
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to run migrations! %v", err)
|
||||
@ -66,11 +67,14 @@ func runMigrations() {
|
||||
if err != nil {
|
||||
// Skip 'no change'. This is fine. Everything is fine.
|
||||
if err.Error() == "no change" {
|
||||
fmt.Println("Database already up to date")
|
||||
return
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("Error running DB Migrations %v", err))
|
||||
}
|
||||
|
||||
fmt.Println("Database migrations complete")
|
||||
}
|
||||
|
||||
func getDbCount(query string, args ...interface{}) (int, error) {
|
||||
|
@ -38,7 +38,7 @@ func enableCors(w *http.ResponseWriter) {
|
||||
}
|
||||
|
||||
// HandleRequests - Boot HTTP!
|
||||
func HandleRequests() {
|
||||
func HandleRequests(port string) {
|
||||
// Create a new router
|
||||
r := mux.NewRouter().StrictSlash(true)
|
||||
|
||||
@ -70,7 +70,8 @@ func HandleRequests() {
|
||||
handler := c.Handler(r)
|
||||
|
||||
// Serve it up!
|
||||
log.Fatal(http.ListenAndServe(":42069", handler))
|
||||
fmt.Printf("Goscrobble listening on port %s", port)
|
||||
log.Fatal(http.ListenAndServe(":"+port, handler))
|
||||
}
|
||||
|
||||
// MIDDLEWARE
|
||||
|
7
migrations/4_mbid.up.sql
Normal file
7
migrations/4_mbid.up.sql
Normal file
@ -0,0 +1,7 @@
|
||||
START TRANSACTION;
|
||||
|
||||
ALTER TABLE albums ADD COLUMN `mbid` VARCHAR(36) DEFAULT NULL;
|
||||
ALTER TABLE artists ADD COLUMN `mbid` VARCHAR(36) DEFAULT NULL;
|
||||
ALTER TABLE tracks ADD COLUMN `mbid` VARCHAR(36) DEFAULT NULL;
|
||||
|
||||
COMMIT;
|
Loading…
Reference in New Issue
Block a user