Add ability to set custom port
This commit is contained in:
Daniel Mason 2021-03-27 19:33:27 +13:00
parent a22f282a6d
commit 08f0cb6c80
Signed by: idanoo
GPG key ID: 387387CDBC02F132
5 changed files with 26 additions and 5 deletions

View file

@ -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) {

View file

@ -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