forked from fergusstrange/embedded-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
94 lines (81 loc) · 2.4 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package embeddedpostgres
import "time"
// Config maintains the runtime configuration for the Postgres process to be created.
type Config struct {
version PostgresVersion
port uint32
database string
username string
password string
runtimePath string
locale string
startTimeout time.Duration
}
// DefaultConfig provides a default set of configuration to be used "as is" or modified using the provided builders.
// The following can be assumed as defaults:
// Version: 12
// Port: 5432
// Database: postgres
// Username: postgres
// Password: postgres
// StartTimeout: 15 Seconds
func DefaultConfig() Config {
return Config{
version: V12,
port: 5432,
database: "postgres",
username: "postgres",
password: "postgres",
startTimeout: 15 * time.Second,
}
}
// Version will set the Postgres binary version.
func (c Config) Version(version PostgresVersion) Config {
c.version = version
return c
}
// Port sets the runtime port that Postgres can be accessed on.
func (c Config) Port(port uint32) Config {
c.port = port
return c
}
// Database sets the database name that will be created.
func (c Config) Database(database string) Config {
c.database = database
return c
}
// Username sets the username that will be used to connect.
func (c Config) Username(username string) Config {
c.username = username
return c
}
// Password sets the password that will be used to connect.
func (c Config) Password(password string) Config {
c.password = password
return c
}
// RuntimePath sets the path that will be used for the extracted Postgres runtime and data directory.
func (c Config) RuntimePath(path string) Config {
c.runtimePath = path
return c
}
// Locale sets the default locale for initdb
func (c Config) Locale(locale string) Config {
c.locale = locale
return c
}
// StartTimeout sets the max timeout that will be used when starting the Postgres process and creating the initial database.
func (c Config) StartTimeout(timeout time.Duration) Config {
c.startTimeout = timeout
return c
}
// PostgresVersion represents the semantic version used to fetch and run the Postgres process.
type PostgresVersion string
// Predefined supported Postgres versions.
const (
V13 = PostgresVersion("13.1.0")
V12 = PostgresVersion("12.1.0-1")
V11 = PostgresVersion("11.6.0-1")
V10 = PostgresVersion("10.11.0-1")
V9 = PostgresVersion("9.6.16-1")
)