From cc9760125aa9e47f1939fc90a6b50b0a2e8e1376 Mon Sep 17 00:00:00 2001 From: lash Date: Sat, 4 Jan 2025 21:02:08 +0000 Subject: [PATCH] Remove unnecessary connection chain step --- .env.example | 1 + cmd/africastalking/main.go | 3 +-- cmd/async/main.go | 3 +-- cmd/http/main.go | 3 +-- cmd/main.go | 3 +-- common/storage.go | 7 +------ devtools/gen/main.go | 3 +-- devtools/store/main.go | 7 +------ internal/storage/storageservice.go | 8 ++------ internal/testutil/engine.go | 8 +------- 10 files changed, 11 insertions(+), 35 deletions(-) diff --git a/.env.example b/.env.example index 0a43945..dae37bc 100644 --- a/.env.example +++ b/.env.example @@ -8,6 +8,7 @@ AT_ENDPOINT=/ussd/africastalking #PostgreSQL DB_CONN=postgres://postgres:strongpass@localhost:5432/urdt_ussd #DB_TIMEZONE=Africa/Nairobi +#DB_SCHEMA=vise #External API Calls CUSTODIAL_URL_BASE=http://localhost:5003 diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index 6035fc6..0d2b8ec 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -80,8 +80,7 @@ func main() { cfg.EngineDebug = true } - menuStorageService := storage.NewMenuStorageService(resourceDir) - menuStorageService = menuStorageService.WithConn(connData) + menuStorageService := storage.NewMenuStorageService(connData, resourceDir) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/cmd/async/main.go b/cmd/async/main.go index 17ea2a1..65e681d 100644 --- a/cmd/async/main.go +++ b/cmd/async/main.go @@ -91,8 +91,7 @@ func main() { cfg.EngineDebug = true } - menuStorageService := storage.NewMenuStorageService(resourceDir) - menuStorageService = menuStorageService.WithConn(connData) + menuStorageService := storage.NewMenuStorageService(connData, resourceDir) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/cmd/http/main.go b/cmd/http/main.go index 69a9c90..2f043e6 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -79,8 +79,7 @@ func main() { cfg.EngineDebug = true } - menuStorageService := storage.NewMenuStorageService(resourceDir) - menuStorageService = menuStorageService.WithConn(connData) + menuStorageService := storage.NewMenuStorageService(connData, resourceDir) rs, err := menuStorageService.GetResource(ctx) if err != nil { diff --git a/cmd/main.go b/cmd/main.go index a475dbe..ad4535b 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -68,8 +68,7 @@ func main() { } resourceDir := scriptDir - menuStorageService := storage.NewMenuStorageService(resourceDir) - menuStorageService = menuStorageService.WithConn(connData) + menuStorageService := storage.NewMenuStorageService(connData, resourceDir) rs, err := menuStorageService.GetResource(ctx) if err != nil { diff --git a/common/storage.go b/common/storage.go index 6ab5211..c7e478b 100644 --- a/common/storage.go +++ b/common/storage.go @@ -32,9 +32,8 @@ type StorageService struct { func NewStorageService(conn storage.ConnData) (*StorageService, error) { svc := &StorageService{ - svc: storage.NewMenuStorageService(""), + svc: storage.NewMenuStorageService(conn, ""), } - svc.SetConn(conn) return svc, nil } @@ -49,7 +48,3 @@ func(ss *StorageService) GetUserdataDb(ctx context.Context) (db.Db, error) { func(ss *StorageService) GetResource(ctx context.Context) (resource.Resource, error) { return nil, errors.New("not implemented") } - -func(ss *StorageService) SetConn(conn storage.ConnData) { - ss.svc = ss.svc.WithConn(conn) -} diff --git a/devtools/gen/main.go b/devtools/gen/main.go index 272fd9c..749f340 100644 --- a/devtools/gen/main.go +++ b/devtools/gen/main.go @@ -55,8 +55,7 @@ func main() { ctx = context.WithValue(ctx, "Database", database) resourceDir := scriptDir - menuStorageService := storage.NewMenuStorageService(resourceDir) - menuStorageService = menuStorageService.WithConn(connData) + menuStorageService := storage.NewMenuStorageService(connData, resourceDir) store, err := menuStorageService.GetUserdataDb(ctx) if err != nil { diff --git a/devtools/store/main.go b/devtools/store/main.go index da988ad..f7f76c6 100644 --- a/devtools/store/main.go +++ b/devtools/store/main.go @@ -53,12 +53,7 @@ func main() { ctx = context.WithValue(ctx, "Database", database) resourceDir := scriptDir - menuStorageService := storage.NewMenuStorageService(resourceDir) - menuStorageService = menuStorageService.WithConn(connData) - if err != nil { - fmt.Fprintf(os.Stderr, "connection string error: %v", err) - os.Exit(1) - } + menuStorageService := storage.NewMenuStorageService(connData, resourceDir) store, err := menuStorageService.GetUserdataDb(ctx) if err != nil { diff --git a/internal/storage/storageservice.go b/internal/storage/storageservice.go index 24d5eff..9148d7c 100644 --- a/internal/storage/storageservice.go +++ b/internal/storage/storageservice.go @@ -34,17 +34,13 @@ type MenuStorageService struct { userDataStore db.Db } -func NewMenuStorageService(resourceDir string) *MenuStorageService { +func NewMenuStorageService(conn ConnData, resourceDir string) *MenuStorageService { return &MenuStorageService{ + conn: conn, resourceDir: resourceDir, } } -func (ms *MenuStorageService) WithConn(conn ConnData) *MenuStorageService { - ms.conn = conn - return ms -} - func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.Db, section string) (db.Db, error) { var newDb db.Db var err error diff --git a/internal/testutil/engine.go b/internal/testutil/engine.go index 3d804ae..2372ce9 100644 --- a/internal/testutil/engine.go +++ b/internal/testutil/engine.go @@ -50,13 +50,7 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) { os.Exit(1) } resourceDir := scriptDir - menuStorageService := storage.NewMenuStorageService(resourceDir) - - menuStorageService.WithConn(conn) - if err != nil { - fmt.Fprintf(os.Stderr, "conn error: %v", err) - os.Exit(1) - } + menuStorageService := storage.NewMenuStorageService(conn, resourceDir) rs, err := menuStorageService.GetResource(ctx) if err != nil {