Skip to content

Commit 15f1997

Browse files
wayjamiamralch
authored andcommitted
Add comment for constants and errors
1 parent a34f431 commit 15f1997

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

common.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ import (
1717
type Logger = log.Logger
1818

1919
const (
20-
MYSQL_DRIVER = "mysql"
21-
SQLITE_DRIVER = "sqlite3"
22-
POSTGRES_DRIVER = "postgres"
20+
// DriverMySQL represents the database driver name of MySQL
21+
DriverMySQL = "mysql"
22+
// DriverSQLite represents the database driver name of SQLite3
23+
DriverSQLite = "sqlite3"
24+
// DriverPostgres represents the databse driver name of Postgres
25+
DriverPostgres = "postgres"
2326
)
2427

28+
// Error codes returned by failures to parse a dsn.
2529
var (
26-
errNoDriverName = errors.New("No driver name")
27-
errEmptyConnURL = errors.New("URL cannot be empty")
28-
errInvalidDSN = errors.New("Invalid DSN")
30+
errNoDriverName = errors.New("no driver name")
31+
errEmptyConnURL = errors.New("url cannot be empty")
32+
errInvalidDSN = errors.New("invalid dsn")
2933
)
3034

3135
// ParseURL parses a URL and returns the database driver and connection string to the database
@@ -36,15 +40,15 @@ func ParseURL(conn string) (string, string, error) {
3640
}
3741

3842
switch driver {
39-
case MYSQL_DRIVER:
43+
case DriverMySQL:
4044
mysqlSource, err := parseMySQL(driver, source)
4145
if err != nil {
4246
return "", "", err
4347
}
4448
return driver, mysqlSource, nil
45-
case SQLITE_DRIVER:
49+
case DriverSQLite:
4650
return driver, source, nil
47-
case POSTGRES_DRIVER:
51+
case DriverPostgres:
4852
return driver, conn, nil
4953
default:
5054
return driver, conn, nil

common_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var _ = Describe("ParseURL", func() {
5151
driver, source, err := prana.ParseURL("")
5252
Expect(driver).To(BeEmpty())
5353
Expect(source).To(BeEmpty())
54-
Expect(err).To(MatchError("URL cannot be empty"))
54+
Expect(err).To(MatchError("url cannot be empty"))
5555
})
5656
})
5757

@@ -60,7 +60,7 @@ var _ = Describe("ParseURL", func() {
6060
driver, source, err := prana.ParseURL("::")
6161
Expect(driver).To(BeEmpty())
6262
Expect(source).To(BeEmpty())
63-
Expect(err).To(MatchError("Invalid DSN"))
63+
Expect(err).To(MatchError("invalid dsn"))
6464
})
6565
})
6666
})

0 commit comments

Comments
 (0)