Skip to content

Commit 92e2202

Browse files
committed
no config file for now
1 parent ed712e0 commit 92e2202

File tree

2 files changed

+33
-80
lines changed

2 files changed

+33
-80
lines changed

dbos/config.go

Lines changed: 0 additions & 80 deletions
This file was deleted.

dbos/dbos.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/hex"
77
"fmt"
88
"log/slog"
9+
"net/url"
910
"os"
1011
"reflect"
1112
"runtime"
@@ -91,6 +92,38 @@ type config struct {
9192
appName string
9293
}
9394

95+
// NewConfig merges configuration from two sources in order of precedence:
96+
// 1. programmatic configuration
97+
// 2. environment variables
98+
// Finally, it applies default values if needed.
99+
func NewConfig(programmaticConfig config) *config {
100+
dbosConfig := &config{}
101+
102+
// Start with environment variables (lowest precedence)
103+
if dbURL := os.Getenv("DBOS_DATABASE_URL"); dbURL != "" {
104+
dbosConfig.databaseURL = dbURL
105+
}
106+
107+
// Override with programmatic configuration (highest precedence)
108+
if len(programmaticConfig.databaseURL) > 0 {
109+
dbosConfig.databaseURL = programmaticConfig.databaseURL
110+
}
111+
if len(programmaticConfig.appName) > 0 {
112+
dbosConfig.appName = programmaticConfig.appName
113+
}
114+
// Copy over parameters that can only be set programmatically
115+
dbosConfig.logger = programmaticConfig.logger
116+
dbosConfig.adminServer = programmaticConfig.adminServer
117+
118+
// Load defaults
119+
if len(dbosConfig.databaseURL) == 0 {
120+
getLogger().Info("DBOS_DATABASE_URL not set, using default: postgres://postgres:${PGPASSWORD}@localhost:5432/dbos?sslmode=disable")
121+
password := url.QueryEscape(os.Getenv("PGPASSWORD"))
122+
dbosConfig.databaseURL = fmt.Sprintf("postgres://postgres:%s@localhost:5432/dbos?sslmode=disable", password)
123+
}
124+
return dbosConfig
125+
}
126+
94127
type LaunchOption func(*config)
95128

96129
func WithLogger(logger *slog.Logger) LaunchOption {

0 commit comments

Comments
 (0)