-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathutil.go
52 lines (43 loc) · 1.06 KB
/
util.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package golangNeo4jBoltDriver
import (
"database/sql/driver"
"errors"
"fmt"
"github.com/johnnadratowski/golang-neo4j-bolt-driver/encoding"
)
// sprintByteHex returns a formatted string of the byte array in hexadecimal
// with a nicely formatted human-readable output
func sprintByteHex(b []byte) string {
output := "\t"
for i, b := range b {
output += fmt.Sprintf("%x", b)
if (i+1)%16 == 0 {
output += "\n\n\t"
} else if (i+1)%4 == 0 {
output += " "
} else {
output += " "
}
}
output += "\n"
return output
}
// driverArgsToMap turns driver.Value list into a parameter map
// for neo4j parameters
func driverArgsToMap(args []driver.Value) (map[string]interface{}, error) {
output := map[string]interface{}{}
for _, arg := range args {
argBytes, ok := arg.([]byte)
if !ok {
return nil, errors.New("You must pass only a gob encoded map to the Exec/Query args")
}
m, err := encoding.Unmarshal(argBytes)
if err != nil {
return nil, err
}
for k, v := range m.(map[string]interface{}) {
output[k] = v
}
}
return output, nil
}