Repository navigation
Expand file tree
/
Copy pathconfig.go
More file actions
62 lines (53 loc) · 1.88 KB
/
Copy pathconfig.go
File metadata and controls
62 lines (53 loc) · 1.88 KB
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
package pglite
import "log/slog"
// User and Database are the only role and database the backend serves: the
// module runs initdb as this user and starts the single-user backend on
// this database.
const (
User = "postgres"
Database = "postgres"
)
// Config configures an instance. The zero value starts a fresh cluster in a
// temporary directory that Close removes.
type Config struct {
// DataDir is the instance directory, holding the cluster under
// pglite/base. It is created if missing; a directory without a cluster
// is initialised. Empty means a temporary directory removed by Close.
DataDir string
// Template is a directory made by CreateTemplate whose cluster is
// copied into DataDir before the start. DataDir must not hold a cluster
// yet.
Template string
// CacheDir holds the extracted installation every instance shares.
// Empty means DefaultCacheDir.
CacheDir string
// Settings are session settings every connection starts with, applied
// before the client's own startup parameters. A setting PostgreSQL
// rejects fails the first connection. For example,
// synchronous_commit=off makes a commit return before its WAL reaches
// disk, which on macOS (where every fsync is a full flush) takes
// several milliseconds; a crash can then lose the last commits, but
// never corrupt the cluster.
Settings map[string]string
// StdoutFile and StderrFile receive the module's standard output and
// PostgreSQL's log. Empty discards them.
StdoutFile string
StderrFile string
// Logger receives the bridge's own messages, such as a crash of the
// module. nil means slog.Default.
Logger *slog.Logger
}
func (c *Config) withDefaults() (Config, error) {
out := *c
if out.CacheDir == "" {
dir, err := DefaultCacheDir()
if err != nil {
return out, err
}
out.CacheDir = dir
}
if out.Logger == nil {
out.Logger = slog.Default()
}
return out, nil
}