Browse Source

add env var checks

pull/1/head
Stephanie Gredell 7 months ago
parent
commit
ce0a71aade
  1. 10
      cmd/systemdesigngame/main.go
  2. 9
      internal/auth/auth.go
  3. 6
      internal/server/server.go

10
cmd/systemdesigngame/main.go

@ -2,19 +2,22 @@ package main @@ -2,19 +2,22 @@ package main
import (
"flag"
"github.com/joho/godotenv"
"fmt"
"html/template"
"net/http"
"os"
"systemdesigngame/internal/auth"
"systemdesigngame/internal/server"
"systemdesigngame/router"
"github.com/joho/godotenv"
)
func main() {
devMode := flag.Bool("dev", false, "load .env (local dev)")
flag.Parse()
fmt.Printf("devmode: %v", *devMode)
if *devMode {
if err := godotenv.Load(); err != nil {
panic("failed to load .env")
@ -24,6 +27,11 @@ func main() { @@ -24,6 +27,11 @@ func main() {
// set up JWT secret used for authentication
auth.JwtSecret = []byte(os.Getenv("JWT_SECRET"))
if len(auth.JwtSecret) == 0 {
panic("JWT_SECRET is not set")
}
tmpl := template.Must(template.ParseGlob("static/*.html"))
server.InitApp()

9
internal/auth/auth.go

@ -38,6 +38,15 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) { @@ -38,6 +38,15 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
clientId := os.Getenv("GITHUB_CLIENT_ID")
redirectURI := os.Getenv("GITHUB_CALLBACK")
if os.Getenv("GITHUB_CLIENT_ID") == "" {
panic("GITHUB_CLIENT_ID is not set")
}
if os.Getenv("GITHUB_CALLBACK") == "" {
panic("GITHUB_CALLBACK is not set")
}
scope := "read:user user:email"
url := fmt.Sprintf(
"https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=%s&scope=%s",

6
internal/server/server.go

@ -10,15 +10,9 @@ import ( @@ -10,15 +10,9 @@ import (
"systemdesigngame/internal/auth"
"systemdesigngame/internal/level"
"time"
"github.com/joho/godotenv"
)
func InitApp() {
if err := godotenv.Load(); err != nil {
log.Fatal("failed to load .env")
}
auth.JwtSecret = []byte(os.Getenv("JWT_SECRET"))
levels, err := level.LoadLevels("data/levels.json")

Loading…
Cancel
Save