-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (58 loc) · 1.13 KB
/
main.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"context"
"fmt"
"os"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)
var (
db *pgxpool.Pool
ctx = context.Background()
)
func initDB() error {
var (
err error
conf *pgxpool.Config
)
conf, err = pgxpool.ParseConfig(os.Getenv("DATABASE_URL"))
if err != nil {
return err
}
conf.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
dataTypeNames := []string{
"http_client_error_code",
"_http_client_error_code",
"http_client_error_code_list",
"_http_client_error_code_list",
}
for _, typeName := range dataTypeNames {
dataType, err := conn.LoadType(ctx, typeName)
if err != nil {
return err
}
conn.TypeMap().RegisterType(dataType)
}
return nil
}
db, err = pgxpool.NewWithConfig(context.Background(), conf)
return err
}
func main() {
err := initDB()
if err != nil {
panic(err)
}
defer db.Close()
trx, err := db.Begin(ctx)
if err != nil {
panic(err)
}
rec, err := NewTestArryWithGo(ctx, trx, HTTPClientErrorCodeList{400})
if err != nil {
_ = trx.Rollback(ctx)
panic(err)
}
_ = trx.Commit(ctx)
fmt.Printf("%#v\n", rec)
}