package main

import (
	"context"
	"log"

	"github.com/gin-gonic/gin"
	"github.com/jackc/pgx/v5"

	user "tutorial.sqlc.dev/app/internal/author"
)

func run() error {
	ctx := context.Background()

	conn, err := pgx.Connect(ctx, "postgres://postgres:supersecretpassword@localhost:5432/sqlc_tutorial")
	if err != nil {
		return err
	}
	defer conn.Close(ctx)

	r := gin.Default()
	userCtl := user.NewController(conn)
	user.Register(r, &userCtl)

	r.Run(":8000")
	return nil
}

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}
