Skip to content

Commit 6b40b35

Browse files
dantleechJack Barton
andauthored
Support specifying the driver (#42)
* Support specifying the driver * Fix CS * Fix order * Try and fix tests * Linting * Map driver * Fix test * Formatting tidy Co-authored-by: Jack Barton <jack.barton@inviqa.com>
1 parent db07f1a commit 6b40b35

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

config/builder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Builder struct {
1212
dBSchema string
1313
dBUser string
1414
dBPass string
15+
dBDriver string
1516
useDbForRetries bool
1617
maintenanceInterval time.Duration
1718
topicNameGenerator topicNameGenerator
@@ -24,6 +25,7 @@ func NewBuilder() *Builder {
2425
topicNameGenerator: defaultTopicNameGenerator,
2526
maintenanceInterval: defaultMaintenanceInterval,
2627
dBPort: 5432,
28+
dBDriver: "postgres",
2729
}
2830
}
2931

config/builder_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestNewBuilder(t *testing.T) {
1717
dBPort: 5432,
1818
maintenanceInterval: time.Hour * 1,
1919
topicNameGenerator: defaultTopicNameGenerator,
20+
dBDriver: "postgres",
2021
}
2122

2223
got := NewBuilder()
@@ -65,6 +66,7 @@ func TestBuilder_Config(t *testing.T) {
6566
},
6667
},
6768
db: Database{
69+
Driver: "postgres",
6870
Host: "postgres",
6971
Port: 15432,
7072
Schema: "schema",
@@ -125,6 +127,7 @@ func TestBuilder_Config(t *testing.T) {
125127
"product": {},
126128
},
127129
db: Database{
130+
Driver: "postgres",
128131
Host: "postgres",
129132
Port: 5432,
130133
Schema: "schema",

config/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Database struct {
4747
Schema string
4848
User string
4949
Pass string
50+
Driver string
5051
}
5152

5253
type TopicKey string
@@ -162,7 +163,15 @@ func (cfg *Config) dsn() string {
162163
sslMode = "verify-full"
163164
}
164165

165-
return fmt.Sprintf("postgres://%s@%s:%d/%s?sslmode=%s", url.UserPassword(cfg.db.User, cfg.db.Pass), cfg.db.Host, cfg.db.Port, cfg.db.Schema, sslMode)
166+
return fmt.Sprintf(
167+
"%s://%s@%s:%d/%s?sslmode=%s",
168+
cfg.db.Driver,
169+
url.UserPassword(cfg.db.User, cfg.db.Pass),
170+
cfg.db.Host,
171+
cfg.db.Port,
172+
cfg.db.Schema,
173+
sslMode,
174+
)
166175
}
167176

168177
func (cfg *Config) addTopics(topics []*KafkaTopic) {
@@ -187,6 +196,7 @@ func (cfg *Config) loadFromBuilder(b *Builder) error {
187196
cfg.db.Pass = b.dBPass
188197
cfg.db.Schema = b.dBSchema
189198
cfg.db.Port = b.dBPort
199+
cfg.db.Driver = b.dBDriver
190200
cfg.MaintenanceInterval = b.maintenanceInterval
191201
cfg.topicNameGenerator = b.topicNameGenerator
192202

config/config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ func TestConfig_dsn(t *testing.T) {
330330
name: "without TLS enabled",
331331
cfg: Config{
332332
db: Database{
333+
Driver: "postgres",
333334
Host: "postgres-db",
334335
Port: 5002,
335336
Schema: "data",
@@ -343,6 +344,7 @@ func TestConfig_dsn(t *testing.T) {
343344
name: "with TLS enabled",
344345
cfg: Config{
345346
db: Database{
347+
Driver: "postgres",
346348
Host: "postgres-db",
347349
Port: 5002,
348350
Schema: "data",
@@ -357,6 +359,7 @@ func TestConfig_dsn(t *testing.T) {
357359
name: "with password that should be encoded",
358360
cfg: Config{
359361
db: Database{
362+
Driver: "postgres",
360363
Host: "postgres-db",
361364
Port: 5002,
362365
Schema: "data",

0 commit comments

Comments
 (0)