-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
42 lines (33 loc) · 987 Bytes
/
context.go
File metadata and controls
42 lines (33 loc) · 987 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
package main
import (
"github.com/jackc/pgx/v5/pgxpool"
"os"
)
type EventListenerContext struct {
DatabaseHostname string
DatabasePort string
DatabaseUsername string
DatabasePassword string
DatabaseName string
DatabasePool *pgxpool.Pool
}
func InitializeContext() *EventListenerContext {
hostname := os.Getenv("EVENT_LISTENER_PG_HOSTNAME")
port := os.Getenv("EVENT_LISTENER_PG_PORT")
username := os.Getenv("EVENT_LISTENER_PG_USERNAME")
password := os.Getenv("EVENT_LISTENER_PG_PASSWORD")
database := os.Getenv("EVENT_LISTENER_PG_DATABASE")
context := EventListenerContext{
DatabaseHostname: hostname,
DatabasePort: port,
DatabaseUsername: username,
DatabasePassword: password,
DatabaseName: database,
}
pool, err := CreateDatabasePool(&context)
if err != nil {
panic(err)
}
context.DatabasePool = pool
return &context
}