@@ -10,53 +10,46 @@ import (
10
10
"syscall"
11
11
"time"
12
12
13
+ "github.com/joho/godotenv"
13
14
"github.com/yaninyzwitty/pulsar-outbox-products-service/controller"
14
15
"github.com/yaninyzwitty/pulsar-outbox-products-service/database"
15
16
"github.com/yaninyzwitty/pulsar-outbox-products-service/helpers"
16
- "github.com/yaninyzwitty/pulsar-outbox-products-service/pkg"
17
17
"github.com/yaninyzwitty/pulsar-outbox-products-service/pulsar"
18
18
"github.com/yaninyzwitty/pulsar-outbox-products-service/router"
19
19
"github.com/yaninyzwitty/pulsar-outbox-products-service/sonyflake"
20
20
)
21
21
22
22
var (
23
- cfg pkg.Config
24
- password string
25
- token string
23
+ password string
24
+ token string
25
+ host = "ep-dark-unit-a2z9twbi-pooler.eu-central-1.aws.neon.tech"
26
+ dbName = "neondb"
27
+ SSLMode = "require"
28
+ pulsarURI = "pulsar+ssl://pulsar-aws-eucentral1.streaming.datastax.com:6651"
29
+ TopicName = "persistent://witty-cluster/default/products_topic"
30
+ port = 3000
26
31
)
27
32
28
33
func main () {
29
- // Load configuration
30
- file , err := os .Open ("my_config.yaml" )
31
- if err != nil {
32
- slog .Error ("failed to open config.yaml" , "error" , err )
34
+ // Load environment variables
35
+ if err := godotenv .Load (); err != nil {
36
+ slog .Error ("failed to load .env" , "error" , err )
33
37
os .Exit (1 )
34
38
}
35
- defer file .Close ()
36
-
37
- if err := cfg .LoadConfig (file ); err != nil {
38
- slog .Error ("failed to load config" , "error" , err )
39
- os .Exit (1 )
40
- }
41
-
42
- // if err := godotenv.Load(); err != nil {
43
- // slog.Error("failed to load .env", "error", err)
44
- // os.Exit(1)
45
- // }
46
- password = os .Getenv ("DB_PASSWORD" )
47
- token = os .Getenv ("PULSAR_TOKEN" )
39
+ password = helpers .GetEnvOrDefault ("DB_PASSWORD" , "" )
40
+ token = helpers .GetEnvOrDefault ("PULSAR_TOKEN" , "" )
48
41
49
42
// Initialize dependencies
50
43
ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
51
44
defer cancel ()
52
45
53
46
dbConfig := database.DbConfig {
54
- Host : cfg . Database . Host ,
47
+ Host : host ,
55
48
Port : 5432 ,
56
- User : cfg . Database . User ,
49
+ User : "neondb_owner" ,
57
50
Password : password ,
58
- DbName : cfg . Database . Database ,
59
- SSLMode : cfg . Database . SSLMode ,
51
+ DbName : dbName , // Fixed typo (dnName → dbName)
52
+ SSLMode : SSLMode ,
60
53
MaxConn : 500 ,
61
54
}
62
55
@@ -78,9 +71,9 @@ func main() {
78
71
}
79
72
80
73
pulsarCfg := pulsar.PulsarConfig {
81
- URI : cfg .Pulsar .URI ,
74
+ URI : pulsarURI , // Used hardcoded URI instead of uninitialized cfg.Pulsar.URI
82
75
Token : token ,
83
- TopicName : cfg .Pulsar .TopicName ,
76
+ TopicName : TopicName , // Used hardcoded topic instead of uninitialized cfg.Pulsar.TopicName
84
77
}
85
78
86
79
pulsarClient , err := pulsarCfg .CreatePulsarConnection (ctx )
@@ -98,19 +91,19 @@ func main() {
98
91
defer producer .Close ()
99
92
100
93
productController := controller .NewProductsController (pool )
101
- router := router .NewRouter (productController )
94
+ appRouter := router .NewRouter (productController ) // Renamed to avoid conflict
102
95
103
96
// Start the server
104
97
server := & http.Server {
105
- Addr : fmt .Sprintf (":%d" , cfg . Server . Port ),
106
- Handler : router ,
98
+ Addr : fmt .Sprintf (":%d" , port ), // This assumes port is set elsewhere
99
+ Handler : appRouter ,
107
100
}
108
101
109
102
stopCh := make (chan os.Signal , 1 )
110
103
signal .Notify (stopCh , os .Interrupt , syscall .SIGTERM )
111
104
112
105
go func () {
113
- slog .Info ("SERVER starting" , "port" , cfg . Server . Port )
106
+ slog .Info ("SERVER starting" , "port" , port )
114
107
if err := server .ListenAndServe (); err != nil && err != http .ErrServerClosed {
115
108
slog .Error ("server error" , "error" , err )
116
109
os .Exit (1 )
0 commit comments