Perbaikan pembacaan data base
This commit is contained in:
@@ -14,6 +14,8 @@ import (
|
||||
v1 "api-service/internal/routes/v1"
|
||||
)
|
||||
|
||||
var dbService database.Service // Global variable to hold the database service instance
|
||||
|
||||
type Server struct {
|
||||
port int
|
||||
db database.Service
|
||||
@@ -29,9 +31,13 @@ func NewServer() *http.Server {
|
||||
port = cfg.Server.Port
|
||||
}
|
||||
|
||||
if dbService == nil { // Check if the database service is already initialized
|
||||
dbService = database.New(cfg) // Initialize only once
|
||||
}
|
||||
|
||||
NewServer := &Server{
|
||||
port: port,
|
||||
db: database.New(cfg),
|
||||
db: dbService, // Use the global database service instance
|
||||
}
|
||||
|
||||
// Declare Server config
|
||||
|
||||
Reference in New Issue
Block a user