MCPcopy Create free account
hub / github.com/cloud-native-go/examples / Run

Method Run

ch05/ch05_08/pglogger.go:60–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58}
59
60func (l *PostgresTransactionLogger) Run() {
61 events := make(chan Event, 16) // Make an events channel
62 l.events = events
63
64 errors := make(chan error, 1) // Make an errors channel
65 l.errors = errors
66
67 go func() { // The INSERT query
68 query := `INSERT INTO transactions
69 (event_type, key, value)
70 VALUES ($1, $2, $3)`
71
72 for e := range events { // Retrieve the next Event
73 _, err := l.db.Exec( // Execute the INSERT query
74 query,
75 e.EventType, e.Key, e.Value)
76
77 if err != nil {
78 errors <- err
79 }
80
81 l.wg.Done()
82 }
83 }()
84}
85
86func (l *PostgresTransactionLogger) Wait() {
87 l.wg.Wait()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected