-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (50 loc) · 1.47 KB
/
main.go
File metadata and controls
64 lines (50 loc) · 1.47 KB
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
package main
import (
"context"
"fmt"
"log/slog"
"os"
"os/signal"
"syscall"
"github.com/arthurdotwork/sqlc/internal/adapters/secondary/repository"
"github.com/arthurdotwork/sqlc/internal/domain"
"github.com/arthurdotwork/sqlc/internal/infrastructure/log"
"github.com/arthurdotwork/sqlc/internal/infrastructure/psql"
"github.com/arthurdotwork/sqlc/internal/infrastructure/queries"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
log.Config(ctx)
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sig
cancel()
}()
if err := run(ctx); err != nil {
slog.ErrorContext(ctx, "failed to run application", log.Err(err))
}
}
func run(ctx context.Context) error {
psqlClient, err := psql.Connect(ctx, "postgres", "postgres", "localhost", "5432", "postgres")
if err != nil {
return fmt.Errorf("failed to connect to psql: %w", err)
}
q, err := queries.Prepare(ctx, psqlClient)
if err != nil {
return fmt.Errorf("failed to prepare queries: %w", err)
}
r := repository.New(psqlClient, q)
svc := domain.NewService(r)
createdAccount, err := svc.CreateAccountAndCredit(ctx)
if err != nil {
return fmt.Errorf("failed to create account and credit: %w", err)
}
account, err := svc.GetAccount(ctx, createdAccount.IBAN)
if err != nil {
return fmt.Errorf("failed to get account: %w", err)
}
slog.InfoContext(ctx, "created and retrieved account", "account", account)
return nil
}