forked from DataDog/dd-trace-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
36 lines (31 loc) · 902 Bytes
/
utils.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
package sql
import (
"database/sql/driver"
"errors"
"sort"
"strings"
)
func newDSNAndService(dsn, service string) string {
return dsn + "|" + service
}
func parseDSNAndService(dsnAndService string) (dsn, service string) {
tab := strings.Split(dsnAndService, "|")
return tab[0], tab[1]
}
// namedValueToValue is a helper function copied from the database/sql package.
func namedValueToValue(named []driver.NamedValue) ([]driver.Value, error) {
dargs := make([]driver.Value, len(named))
for n, param := range named {
if len(param.Name) > 0 {
return nil, errors.New("sql: driver does not support the use of Named Parameters")
}
dargs[n] = param.Value
}
return dargs, nil
}
// stringInSlice returns true if the string s is in the list.
func stringInSlice(list []string, s string) bool {
sort.Strings(list)
i := sort.SearchStrings(list, s)
return i < len(list) && list[i] == s
}