Skip to content

Commit 11d830e

Browse files
author
Kenneth Shaw
committed
General code cleanup/maintenance
1 parent 03f3101 commit 11d830e

File tree

6 files changed

+34
-28
lines changed

6 files changed

+34
-28
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
example/example
2+
coverage.out

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func main() {
191191
log.Fatal(err)
192192
}
193193

194-
fmt.Println(">> got: %s\n", name)
194+
fmt.Printf(">> got: %s\n", name)
195195
}
196196
```
197197

contrib/meta.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
SRC=$(realpath $(cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../)
4+
5+
pushd $SRC &> /dev/null
6+
7+
gometalinter \
8+
--disable=aligncheck \
9+
--disable=goconst \
10+
--enable=misspell \
11+
--enable=gofmt \
12+
--deadline=100s \
13+
--cyclo-over=15 \
14+
--sort=path \
15+
--exclude='^url\.go.*function Parse\(\).*\(gocyclo\)$' \
16+
./...
17+
18+
popd &> /dev/null

dburl_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ func TestParse(t *testing.T) {
9090
{`sq://path/to/file.sqlite3`, `sqlite3`, `path/to/file.sqlite3`},
9191
{`sq:path/to/file.sqlite3`, `sqlite3`, `path/to/file.sqlite3`},
9292
{`sq:./path/to/file.sqlite3`, `sqlite3`, `./path/to/file.sqlite3`},
93+
{`sq://./path/to/file.sqlite3?loc=auto`, `sqlite3`, `./path/to/file.sqlite3?loc=auto`},
9394

94-
{`oracle://user:pass@localhost/xe.oracle.docker`, `ora`, `user/pass@localhost/xe.oracle.docker`}, // 38
95+
{`oracle://user:pass@localhost/xe.oracle.docker`, `ora`, `user/pass@localhost/xe.oracle.docker`}, // 39
9596
}
9697

9798
for i, test := range tests {

dsn.go

+11-25
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,13 @@ func GenFromURL(urlstr string) func(*URL) (string, error) {
9393
}
9494
}
9595

96+
// GenOpaque generates a opaque file path DSN from the passed URL.
97+
func GenOpaque(u *URL) (string, error) {
98+
return u.Opaque + genQueryOptions(u.Query()), nil
99+
}
100+
96101
// GenPostgres generates a postgres DSN from the passed URL.
97102
func GenPostgres(u *URL) (string, error) {
98-
q := u.Query()
99-
100103
host, port, dbname := u.Hostname(), u.Port(), strings.TrimPrefix(u.Path, "/")
101104
if host == "." {
102105
return "", ErrPostgresDoesNotSupportRelativePath
@@ -111,6 +114,7 @@ func GenPostgres(u *URL) (string, error) {
111114
host, port, dbname = resolveDir(stdpath.Join(host, dbname))
112115
}
113116

117+
q := u.Query()
114118
q.Set("host", host)
115119
q.Set("port", port)
116120
q.Set("dbname", dbname)
@@ -298,22 +302,6 @@ func GenOracle(u *URL) (string, error) {
298302
return un + "@" + dsn, nil
299303
}
300304

301-
// GenOpaque generates a opaque file path DSN from the passed URL.
302-
func GenOpaque(u *URL) (string, error) {
303-
dsn := u.Opaque
304-
if u.Host != "" {
305-
dsn = u.Host + u.Path
306-
}
307-
308-
// add params
309-
params := u.Query().Encode()
310-
if len(params) > 0 {
311-
dsn += "?" + params
312-
}
313-
314-
return dsn, nil
315-
}
316-
317305
// GenFirebird generates a firebirdsql DSN from the passed URL.
318306
func GenFirebird(u *URL) (string, error) {
319307
z := &url.URL{
@@ -330,11 +318,7 @@ func GenFirebird(u *URL) (string, error) {
330318

331319
// GenADODB generates a adodb DSN from the passed URL.
332320
func GenADODB(u *URL) (string, error) {
333-
q := u.Query()
334-
q.Set("Provider", u.Hostname())
335-
q.Set("Port", u.Port())
336-
337-
// grab dbname
321+
// grab data source
338322
dsname, dbname := strings.TrimPrefix(u.Path, "/"), ""
339323
if dsname == "" {
340324
dsname = "."
@@ -348,6 +332,9 @@ func GenADODB(u *URL) (string, error) {
348332
}
349333
}
350334

335+
q := u.Query()
336+
q.Set("Provider", u.Hostname())
337+
q.Set("Port", u.Port())
351338
q.Set("Data Source", dsname)
352339
q.Set("Database", dbname)
353340

@@ -364,7 +351,6 @@ func GenADODB(u *URL) (string, error) {
364351
// GenODBC generates a odbc DSN from the passed URL.
365352
func GenODBC(u *URL) (string, error) {
366353
q := u.Query()
367-
368354
q.Set("Driver", "{"+strings.Replace(u.Proto, "+", " ", -1)+"}")
369355
q.Set("Server", u.Hostname())
370356

@@ -525,7 +511,7 @@ func genOptionsODBC(q url.Values, skipWhenEmpty bool, ignore ...string) string {
525511
return genOptions(q, "", "=", ";", ",", skipWhenEmpty, ignore...)
526512
}
527513

528-
// genQueryOptions generatens standard query options.
514+
// genQueryOptions generates standard query options.
529515
func genQueryOptions(q url.Values) string {
530516
if s := q.Encode(); s != "" {
531517
return "?" + s

example/example.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ func main() {
2121
log.Fatal(err)
2222
}
2323

24-
fmt.Println(">> got: %s\n", name)
24+
fmt.Printf(">> got: %s\n", name)
2525
}

0 commit comments

Comments
 (0)