58 lines
1.0 KiB
Go
58 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
"github.com/joho/godotenv"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var pool *pgxpool.Pool
|
|
var ctx = context.Background()
|
|
|
|
type Task struct {
|
|
Id int `json:"id"`
|
|
Text string `json:"text"`
|
|
Completed bool `json:"completed"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func init() {
|
|
if err := godotenv.Load(); err != nil {
|
|
log.Fatal("Error al cargar el archivo .env", err)
|
|
}
|
|
|
|
var err error
|
|
pool, err = pgxpool.New(ctx, os.Getenv("PG_FROM_DB_URL"))
|
|
if err != nil {
|
|
log.Fatal("Unable to connect to database:", err)
|
|
}
|
|
|
|
if err := pool.Ping(ctx); err != nil {
|
|
log.Fatal("Unable to ping database:", err)
|
|
}
|
|
|
|
fmt.Println("Connected to PostgreSQL database!")
|
|
}
|
|
|
|
func main() {
|
|
app := &cli.App{
|
|
Name: "Go Todo App",
|
|
Usage: "A simple CLI program to manage your tasks",
|
|
Commands: []*cli.Command{
|
|
// We'll add commands here
|
|
},
|
|
}
|
|
|
|
err := app.Run(os.Args)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|