allow the BuildConnStr to be accessed by different packages
This commit is contained in:
parent
c34fe192c6
commit
b0c9197ce4
@ -36,7 +36,23 @@ type MenuStorageService struct {
|
||||
userDataStore db.Db
|
||||
}
|
||||
|
||||
func NewMenuStorageService(conn ConnData, resourceDir string) *MenuStorageService {
|
||||
func BuildConnStr() string {
|
||||
host := initializers.GetEnv("DB_HOST", "localhost")
|
||||
user := initializers.GetEnv("DB_USER", "postgres")
|
||||
password := initializers.GetEnv("DB_PASSWORD", "")
|
||||
dbName := initializers.GetEnv("DB_NAME", "")
|
||||
port := initializers.GetEnv("DB_PORT", "5432")
|
||||
|
||||
connString := fmt.Sprintf(
|
||||
"postgres://%s:%s@%s:%s/%s",
|
||||
user, password, host, port, dbName,
|
||||
)
|
||||
logg.Debugf("pg conn string", "conn", connString)
|
||||
|
||||
return connString
|
||||
}
|
||||
|
||||
func NewMenuStorageService(dbDir string, resourceDir string) *MenuStorageService {
|
||||
return &MenuStorageService{
|
||||
conn: conn,
|
||||
resourceDir: resourceDir,
|
||||
@ -58,7 +74,7 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.D
|
||||
|
||||
|
||||
if database == "postgres" {
|
||||
connStr := buildConnStr()
|
||||
connStr := BuildConnStr()
|
||||
|
||||
// Ensure the schema exists
|
||||
err = ensureSchemaExists(ctx, connStr, schema)
|
||||
|
Loading…
Reference in New Issue
Block a user