-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (36 loc) · 881 Bytes
/
Copy pathmain.go
File metadata and controls
49 lines (36 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"context"
"flag"
"log"
"os"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
cmdinternal "github.com/MarioCarrion/videos/2023/transaction-in-context/cmd/internal"
"github.com/MarioCarrion/videos/2023/transaction-in-context/internal/postgresql"
)
func main() {
var userID string
flag.StringVar(&userID, "id", "", "id of user to select")
flag.Parse()
if userID == "" {
flag.PrintDefaults()
os.Exit(0)
}
id, err := uuid.Parse(userID)
if err != nil {
log.Fatalln("UUID Parsing error:", err)
}
//-
ctx := context.Background()
conn, err := pgx.Connect(ctx, cmdinternal.NewConnString())
if err != nil {
log.Fatalln("Connection error:", err)
}
userRoleRepo := postgresql.NewUserRole(conn)
user, err := userRoleRepo.Select(ctx, id)
if err != nil {
log.Fatalln("userRoleRepo.Select", err)
}
cmdinternal.Print(&user)
}