-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
69 lines (60 loc) · 2.41 KB
/
options.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
/*
* COPYRIGHT 2020 Brightgate Inc. All rights reserved.
*
* This copyright notice is Copyright Management Information under 17 USC 1202
* and is included to protect this work and deter copyright infringement.
* Removal or alteration of this Copyright Management Information without the
* express written permission of Brightgate Inc is prohibited, and any
* such unauthorized removal or alteration will be a violation of federal law.
*/
package briefpg
//
// This pattern was cribbed from zap's Option interface
//
// Option describes a generic interface for options.
type Option interface {
apply(*BriefPG) error
}
// optionFunc wraps a func so it satisfies the Option interface.
type optionFunc func(*BriefPG) error
func (f optionFunc) apply(bpg *BriefPG) error {
return f(bpg)
}
// OptPostgresPath returns an Option which sets the location to look for Postgres.
// If a satisfactory Postgres is not found at that location, returns an error.
// This option can only be set before calling Start().
func OptPostgresPath(dir string) Option {
return optionFunc(func(bpg *BriefPG) error {
return bpg.setPostgresPath(dir)
})
}
// OptLogFunc returns an Option which sets the logging function for BriefPG.
// A typical usage is err := bpg.SetOption(briefpg.OptLogFunc(t.Logf)) to
// connect BriefPG to the test's logging.
func OptLogFunc(logf LogFunction) Option {
return optionFunc(func(bpg *BriefPG) error {
bpg.logf = logf
return nil
})
}
// OptTmpDir returns an Option which sets the temporary directory where the
// postgres database will put its files. If no user-specified OptTmpDir is
// set, ioutil.TempDir is used to create one automatically. The caller is
// responsible for making the TempDir. This option can only be set before
// calling Start(). If the TmpDir is specified, and user-created, it will not
// be cleaned up when calling Fini() or MustFini(). If automatically created,
// it will be automatically cleaned up.
func OptTmpDir(dir string) Option {
return optionFunc(func(bpg *BriefPG) error {
return bpg.setTmpDir(dir)
})
}
// OptPostgresEncoding returns an Option which sets the -E argument to the
// postgres 'initdb' command; this sets the default encoding for new databases.
// If not set, the default is UNICODE. This option can only be set before
// calling Start().
func OptPostgresEncoding(enc string) Option {
return optionFunc(func(bpg *BriefPG) error {
return bpg.setPostgresEncoding(enc)
})
}