48 lines
1 KiB
Go
48 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"git.wittern.io/public/goth-stack/db"
|
|
"git.wittern.io/public/goth-stack/handler"
|
|
"git.wittern.io/public/goth-stack/view"
|
|
"github.com/joho/godotenv"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
var Username = "User"
|
|
|
|
func main() {
|
|
godotenv.Load()
|
|
pqUser := os.Getenv("POSTGRES_USER")
|
|
pqDB := os.Getenv("POSTGRES_DB")
|
|
pqPASS := os.Getenv("POSTGRES_PASSWORD")
|
|
pqHost := os.Getenv("POSTGRES_HOST")
|
|
pqPort := os.Getenv("POSTGRES_PORT")
|
|
webPort := os.Getenv("WEB_PORT")
|
|
if pqHost == "" {
|
|
pqHost = "127.0.0.1"
|
|
}
|
|
|
|
e := echo.New()
|
|
err := godotenv.Load()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
Username = os.Getenv("USERNAME")
|
|
|
|
view.Username = Username
|
|
connStr := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Europe/Amsterdam", pqHost, pqUser, pqPASS, pqDB, pqPort)
|
|
|
|
db, err := db.NewClient(connStr)
|
|
if err != nil {
|
|
slog.Error("failed to open database", "Error", err)
|
|
panic(err)
|
|
}
|
|
h := handler.NewHandler(db)
|
|
|
|
handler.AddRoutes(h, e)
|
|
e.Start(webPort)
|
|
}
|