Issues changing defaults via DefaultConfig()
jeremybusk opened this issue · comments
Jeremy Busk commented
I'm trying to change the defaults via DefaultConfig and is not working as per README.
Maybe you can point me in the right direction.
go version
go version go1.17.1 linux/amd64
package main
import (
"bytes"
"fmt"
"time"
"github.com/fergusstrange/embedded-postgres"
)
func main() {
V12 := "12.10.0"
logger := &bytes.Buffer{}
postgres := embeddedpostgres.NewDatabase(DefaultConfig().
Username("beer").
Password("wine").
Database("gin").
Version(V12).
RuntimePath("/tmp").
BinaryRepositoryURL("https://repo1.maven.org/maven2").
Port(9876).
StartTimeout(45 * time.Second).
Logger(logger))
err := postgres.Start()
fmt.Println(err)
}
go build a.go
# command-line-arguments
./a.go:14:44: undefined: DefaultConfig
Any idea what I'm doing wrong? Thanks! Great project BTW!
Jeremy Busk commented
Got it figured out. Here is some example code that for those interested.
package main
/*
https://github.com/fergusstrange/embedded-postgres
https://pkg.go.dev/github.com/fergusstrange/embedded-postgres#section-readme
https://github.com/zonkyio/embedded-postgres
https://mvnrepository.com/artifact/io.zonky.test.postgres/embedded-postgres-binaries-bom
*/
import (
"bytes"
"fmt"
"time"
"github.com/fergusstrange/embedded-postgres"
)
func main() {
runseconds := 60
// Version("14.2.0").
// Version("13.6.0").
// Version("12.10.0").
logger := &bytes.Buffer{}
conf := embeddedpostgres.DefaultConfig().
Username("demo").
Password("demo").
Database("demo").
Version("14.2.0").
RuntimePath("./pgdata").
BinaryRepositoryURL("https://repo1.maven.org/maven2").
Port(9999).
StartTimeout(15 * time.Second).
Logger(logger)
postgres := embeddedpostgres.NewDatabase(conf)
err := postgres.Start()
fmt.Println(err)
fmt.Printf("Running postgres server for %d seconds.", runseconds)
time.Sleep(time.Duration(runseconds) * time.Second)
errstop := postgres.Stop()
fmt.Println(errstop)
}
Fergus Strange commented
Alas, that looks like I've missed some important documentation. Thanks for this @jeremybusk I'll get the README updated.