-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.go
61 lines (54 loc) · 1.51 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
package gitdb
import (
"errors"
"time"
)
// Config represents configuration options for GitDB
type Config struct {
ConnectionName string
DBPath string
OnlineRemote string
EncryptionKey string
SyncInterval time.Duration
User *User
Factory func(string) Model
EnableUI bool
UIPort int
// Mock is a hook for testing apps. If true will return a Mock DB connection
Mock bool
Driver dbDriver
}
const defaultConnectionName = "default"
const defaultSyncInterval = time.Second * 5
const defaultUserName = "ghost"
const defaultUserEmail = "[email protected]"
const defaultUIPort = 4120
// NewConfig constructs a *Config
func NewConfig(dbPath string) *Config {
return &Config{
DBPath: dbPath,
SyncInterval: defaultSyncInterval,
User: NewUser(defaultUserName, defaultUserEmail),
ConnectionName: defaultConnectionName,
UIPort: defaultUIPort,
Driver: &gitDriver{driver: &gitBinaryDriver{}},
}
}
// NewConfigWithLocalDriver constructs a *Config
func NewConfigWithLocalDriver(dbPath string) *Config {
return &Config{
DBPath: dbPath,
SyncInterval: defaultSyncInterval,
User: NewUser(defaultUserName, defaultUserEmail),
ConnectionName: defaultConnectionName,
UIPort: defaultUIPort,
Driver: &localDriver{},
}
}
// Validate returns an error is *Config.DBPath is not set
func (c *Config) Validate() error {
if len(c.DBPath) == 0 {
return errors.New("Config.DbPath must be set")
}
return nil
}