@@ -93,10 +93,13 @@ func GenFromURL(urlstr string) func(*URL) (string, error) {
93
93
}
94
94
}
95
95
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
+
96
101
// GenPostgres generates a postgres DSN from the passed URL.
97
102
func GenPostgres (u * URL ) (string , error ) {
98
- q := u .Query ()
99
-
100
103
host , port , dbname := u .Hostname (), u .Port (), strings .TrimPrefix (u .Path , "/" )
101
104
if host == "." {
102
105
return "" , ErrPostgresDoesNotSupportRelativePath
@@ -111,6 +114,7 @@ func GenPostgres(u *URL) (string, error) {
111
114
host , port , dbname = resolveDir (stdpath .Join (host , dbname ))
112
115
}
113
116
117
+ q := u .Query ()
114
118
q .Set ("host" , host )
115
119
q .Set ("port" , port )
116
120
q .Set ("dbname" , dbname )
@@ -298,22 +302,6 @@ func GenOracle(u *URL) (string, error) {
298
302
return un + "@" + dsn , nil
299
303
}
300
304
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
-
317
305
// GenFirebird generates a firebirdsql DSN from the passed URL.
318
306
func GenFirebird (u * URL ) (string , error ) {
319
307
z := & url.URL {
@@ -330,11 +318,7 @@ func GenFirebird(u *URL) (string, error) {
330
318
331
319
// GenADODB generates a adodb DSN from the passed URL.
332
320
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
338
322
dsname , dbname := strings .TrimPrefix (u .Path , "/" ), ""
339
323
if dsname == "" {
340
324
dsname = "."
@@ -348,6 +332,9 @@ func GenADODB(u *URL) (string, error) {
348
332
}
349
333
}
350
334
335
+ q := u .Query ()
336
+ q .Set ("Provider" , u .Hostname ())
337
+ q .Set ("Port" , u .Port ())
351
338
q .Set ("Data Source" , dsname )
352
339
q .Set ("Database" , dbname )
353
340
@@ -364,7 +351,6 @@ func GenADODB(u *URL) (string, error) {
364
351
// GenODBC generates a odbc DSN from the passed URL.
365
352
func GenODBC (u * URL ) (string , error ) {
366
353
q := u .Query ()
367
-
368
354
q .Set ("Driver" , "{" + strings .Replace (u .Proto , "+" , " " , - 1 )+ "}" )
369
355
q .Set ("Server" , u .Hostname ())
370
356
@@ -525,7 +511,7 @@ func genOptionsODBC(q url.Values, skipWhenEmpty bool, ignore ...string) string {
525
511
return genOptions (q , "" , "=" , ";" , "," , skipWhenEmpty , ignore ... )
526
512
}
527
513
528
- // genQueryOptions generatens standard query options.
514
+ // genQueryOptions generates standard query options.
529
515
func genQueryOptions (q url.Values ) string {
530
516
if s := q .Encode (); s != "" {
531
517
return "?" + s
0 commit comments