Haystack/backend/main.go

40 lines
595 B
Go

package main
import (
"fmt"
"net/http"
"os"
"screenmark/screenmark/models"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
panic(err)
}
db, err := models.InitDatabase()
if err != nil {
panic(err)
}
router := setupRouter(db)
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)
}
}