This repository has been archived by the owner on May 21, 2024. It is now read-only.
/
setting.go
116 lines (97 loc) · 2 KB
/
setting.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package typpostgres
const (
defaultDockerImage = "postgres"
defaultDockerName = "postgres"
defaultConfigName = "PG"
defaultDBName = "sample"
defaultUser = "postgres"
defaultPassword = "pgpass"
defaultHost = "localhost"
defaultPort = 5432
defaultMigrationSrc = "scripts/db/migration"
defaultSeedSrc = "scripts/db/seed"
)
// Settings for postgres
type Settings struct {
Ctor string
DockerName string
DockerImage string
ConfigName string
DBName string
User string
Password string
Host string
Port int
MigrationSrc string
SeedSrc string
}
// GetDockerName from setting
func GetDockerName(s *Settings) string {
if s.DockerName == "" {
return defaultDockerName
}
return s.DockerName
}
// GetDockerImage from setting
func GetDockerImage(s *Settings) string {
if s.DockerImage == "" {
return defaultDockerImage
}
return s.DockerImage
}
// GetConfigName from setting
func GetConfigName(s *Settings) string {
if s.ConfigName == "" {
return defaultConfigName
}
return s.ConfigName
}
// GetDBName from setting
func GetDBName(s *Settings) string {
if s.DBName == "" {
return defaultDBName
}
return s.DBName
}
// GetUser from setting
func GetUser(s *Settings) string {
if s.User == "" {
return defaultUser
}
return s.User
}
// GetPassword from setting
func GetPassword(s *Settings) string {
if s.Password == "" {
return defaultPassword
}
return s.Password
}
// GetHost from setting
func GetHost(s *Settings) string {
if s.Host == "" {
return defaultHost
}
return s.Host
}
// GetPort from setting
func GetPort(s *Settings) int {
if s.Port == 0 {
return defaultPort
}
return s.Port
}
// GetMigrationSrc from setting if available or the default value
func GetMigrationSrc(s *Settings) string {
if s.MigrationSrc == "" {
return defaultMigrationSrc
}
return s.MigrationSrc
}
// GetSeedSrc from setting if available or the default value
func GetSeedSrc(s *Settings) string {
if s.SeedSrc == "" {
return defaultSeedSrc
}
return s.SeedSrc
}