forked from eoscanada/eos-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postprocess.go
39 lines (30 loc) · 907 Bytes
/
postprocess.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
package p2p
import (
"encoding/json"
"fmt"
"github.com/eoscanada/eos-go"
)
type PostProcessable struct {
Route *Route `json:"route"`
P2PMessageEnvelope *eos.P2PMessageEnvelope `json:"p2p_message_envelope"`
}
type Handler interface {
Handle(msg PostProcessable)
}
type HandlerFunc func(msg PostProcessable)
func (f HandlerFunc) Handle(msg PostProcessable) {
f(msg)
}
// LoggerHandler logs the messages back and forth.
var LoggerHandler = HandlerFunc(func(msg PostProcessable) {
data, error := json.Marshal(msg)
if error != nil {
fmt.Println("logger plugin err: ", error)
return
}
fmt.Println("logger - message : ", string(data))
})
// StringLoggerHandler simply prints the messages as they go through the client.
var StringLoggerHandler = HandlerFunc(func(msg PostProcessable) {
fmt.Printf("Received message %T\n", msg.P2PMessageEnvelope.P2PMessage)
})