66 "encoding/hex"
77 "fmt"
88 "log/slog"
9+ "net/url"
910 "os"
1011 "reflect"
1112 "runtime"
@@ -92,6 +93,7 @@ func getLogger() *slog.Logger {
9293type config struct {
9394 logger * slog.Logger
9495 adminServer bool
96+ databaseURL string
9597}
9698
9799type LaunchOption func (* config )
@@ -108,6 +110,12 @@ func WithAdminServer() LaunchOption {
108110 }
109111}
110112
113+ func WithDatabaseURL (url string ) LaunchOption {
114+ return func (config * config ) {
115+ config .databaseURL = url
116+ }
117+ }
118+
111119func Launch (options ... LaunchOption ) error {
112120 if dbos != nil {
113121 fmt .Println ("warning: DBOS instance already initialized, skipping re-initialization" )
@@ -139,7 +147,18 @@ func Launch(options ...LaunchOption) error {
139147 APP_ID = os .Getenv ("DBOS__APPID" )
140148
141149 // Create the system database
142- systemDB , err := NewSystemDatabase ()
150+ var databaseURL string
151+ if config .databaseURL != "" {
152+ databaseURL = config .databaseURL
153+ } else {
154+ databaseURL = os .Getenv ("DBOS_DATABASE_URL" )
155+ if databaseURL == "" {
156+ fmt .Println ("DBOS_DATABASE_URL not set, using default: postgres://postgres:${PGPASSWORD}@localhost:5432/dbos?sslmode=disable" )
157+ password := url .QueryEscape (os .Getenv ("PGPASSWORD" ))
158+ databaseURL = fmt .Sprintf ("postgres://postgres:%s@localhost:5432/dbos?sslmode=disable" , password )
159+ }
160+ }
161+ systemDB , err := NewSystemDatabase (databaseURL )
143162 if err != nil {
144163 return NewInitializationError (fmt .Sprintf ("failed to create system database: %v" , err ))
145164 }
0 commit comments