handler.go
1.2 KB
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
package goqueue
import (
rawjson "encoding/json"
"fmt"
"github.com/linmadan/egglib-go/utils/json"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/blockChain/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/blockChain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log"
)
func UpToChainHandler(k, v string) error {
log.Logger.Debug(fmt.Sprintf("%s", v), map[string]interface{}{"handler": "UptoChain"})
blockChainService := service.NewBlockChainService(nil)
upChainCommand := &command.UpChainCommand{}
err := json.UnmarshalFromString(v, upChainCommand)
if err != nil {
return err
}
_, err = blockChainService.UpChain(upChainCommand)
return err
}
func FilterTopicHandler(topic string, handler func(string, string) error) func(string, string) error {
return func(k string, v string) error {
raw := &RawData{}
err := json.UnmarshalFromString(v, raw)
if err != nil {
return err
}
if raw.Topic != topic {
return nil
}
return handler(k, string(raw.Data))
}
}
type RawData struct {
Topic string `json:"topic"`
Data rawjson.RawMessage `json:"data"`
}