package main

import (
	"context"
	"log"

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

	"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()
	authorCtl := author.NewController(conn)
	author.Register(r, &authorCtl)

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

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