benerin error

This commit is contained in:
farrel
2026-09-22 14:17:55 +07:00
parent ece60afe1d
commit c7e17bf89e
11 changed files with 144 additions and 0 deletions
View File
+35
View File
@@ -0,0 +1,35 @@
package main
import (
"context"
"fmt"
"os"
"5803025029/w04/internal/config"
"5803025029/w04/internal/database"
)
func main() {
if err := config.LoadEnv(); err != nil {
fmt.Fprintf(os.Stderr, "Unable to load env: %v\n", err)
os.Exit(1)
}
conn, err := database.Connect()
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
defer conn.Close(context.Background())
var name string
var weight int64
err = conn.QueryRow(context.Background(), "select name, weight from widgets where id=$1", 42).Scan(&name, &weight)
if err != nil {
fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
os.Exit(1)
}
fmt.Println(name, weight)
}