GoScrobble/cmd/go-scrobble/main.go
2021-03-26 12:21:28 +13:00

45 lines
878 B
Go

package main
import (
"log"
"os"
"strconv"
"strings"
"time"
"git.m2.nz/go-scrobble/internal/goscrobble"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
// Store JWT secret
goscrobble.JwtToken = []byte(os.Getenv("JWT_SECRET"))
// 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"), ",")
// // Boot up DB connection for life of application
goscrobble.InitDb()
defer goscrobble.CloseDbConn()
// Boot up API webserver \o/
goscrobble.HandleRequests()
}