-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
52 lines (45 loc) · 1015 Bytes
/
util.go
File metadata and controls
52 lines (45 loc) · 1015 Bytes
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 goriffle
import (
"fmt"
"math/rand"
"time"
)
const (
maxId int64 = 1 << 53
)
func init() {
rand.Seed(time.Now().UnixNano())
}
// NewID generates a random WAMP uint.
func newID() uint {
return uint(rand.Int63n(maxId))
}
// func PprintMap(m interface{}) {
// if b, err := jSON.MarshalIndent(m, "", " "); err != nil {
// fmt.Println("error:", err)
// } else {
// //log.Printf("%s", string(m))
// }
// }
func formatUnexpectedMessage(msg message, expected messageType) string {
s := fmt.Sprintf("received unexpected %s message while waiting for %s", msg.messageType(), expected)
switch m := msg.(type) {
case *abort:
s += ": " + string(m.Reason)
s += formatUnknownMap(m.Details)
return s
case *goodbye:
s += ": " + string(m.Reason)
s += formatUnknownMap(m.Details)
return s
}
return s
}
func formatUnknownMap(m map[string]interface{}) string {
s := ""
for k, v := range m {
// TODO: reflection to recursively check map
s += fmt.Sprintf(" %s=%v", k, v)
}
return s
}