48 lines
818 B
Go
48 lines
818 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"screenmark/screenmark/middleware"
|
|
"screenmark/screenmark/models"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
func main() {
|
|
err := godotenv.Load()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
jwtSecret := os.Getenv("JWT_SECRET")
|
|
if jwtSecret == "" {
|
|
panic("JWT_SECRET environment variable not set")
|
|
}
|
|
|
|
jwtManager := middleware.NewJwtManager([]byte(jwtSecret))
|
|
|
|
db, err := models.InitDatabase()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
router := setupRouter(db, jwtManager)
|
|
|
|
port, exists := os.LookupEnv("PORT")
|
|
if !exists {
|
|
panic("no port can be found")
|
|
}
|
|
|
|
portWithColon := fmt.Sprintf(":%s", port)
|
|
|
|
logger := createLogger("Main", os.Stdout)
|
|
|
|
logger.Info("Serving router", "port", portWithColon)
|
|
err = http.ListenAndServe(portWithColon, router)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|