2021-03-23 08:43:44 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-03-25 05:15:01 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
2021-03-25 23:21:28 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2021-03-25 05:15:01 +00:00
|
|
|
|
2021-03-23 08:43:44 +00:00
|
|
|
"git.m2.nz/go-scrobble/internal/goscrobble"
|
2021-03-25 05:15:01 +00:00
|
|
|
"github.com/joho/godotenv"
|
2021-03-23 08:43:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2021-03-25 05:15:01 +00:00
|
|
|
err := godotenv.Load()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error loading .env file")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store JWT secret
|
|
|
|
goscrobble.JwtToken = []byte(os.Getenv("JWT_SECRET"))
|
|
|
|
|
2021-03-25 23:21:28 +00:00
|
|
|
// Store JWT expiry
|
|
|
|
goscrobble.JwtExpiry = 86400
|
|
|
|
jwtExpiryStr := os.Getenv("JWT_EXPIRY")
|
|
|
|
if jwtExpiryStr != "" {
|
|
|
|
i, err := strconv.ParseFloat(jwtExpiryStr, 64)
|
|
|
|
if err != nil {
|
|
|
|
panic("Invalid JWT_EXPIRY value")
|
|
|
|
}
|
|
|
|
|
|
|
|
goscrobble.JwtExpiry = time.Duration(i) * time.Second
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore reverse proxies
|
|
|
|
goscrobble.ReverseProxies = strings.Split(os.Getenv("REVERSE_PROXIES"), ",")
|
|
|
|
|
2021-03-24 03:29:35 +00:00
|
|
|
// // Boot up DB connection for life of application
|
2021-03-24 09:28:05 +00:00
|
|
|
goscrobble.InitDb()
|
|
|
|
defer goscrobble.CloseDbConn()
|
2021-03-23 08:43:44 +00:00
|
|
|
|
|
|
|
// Boot up API webserver \o/
|
|
|
|
goscrobble.HandleRequests()
|
|
|
|
}
|