util.go 1 KB
Newer Older
“李磊”'s avatar
“李磊” committed
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
package pluginrpc

import (
	"time"

	uuidgen "github.com/satori/go.uuid"

	pb "linkfog.com/pluginx/proto"
)

func NewReq(from, to, function string, data []byte) *pb.Req {
	req := &pb.Req{}
	req.Header = &pb.Header{
		UUID:      uuidgen.NewV4().String(),
		Timestamp: time.Now().Unix(),
		From:      from,
		To:        to,
		Func:      function,
	}
	req.Data = data
	return req
}

func NewFileStream(from, to, function, name, purpose string) *pb.FileStream {
	fs := &pb.FileStream{}
	fs.Header = &pb.Header{
		UUID:      uuidgen.NewV4().String(),
		Timestamp: time.Now().Unix(),
		From:      from,
		To:        to,
		Func:      function,
	}
	fs.Name = name
	fs.Purpose = purpose
	return fs
}

func NewRes(req *pb.Req, code int32, desc string, data []byte) *pb.Res {
	res := &pb.Res{}
	res.Header = &pb.Header{
		UUID:      req.Header.UUID,
		Timestamp: time.Now().Unix(),
		From:      req.Header.To,
		To:        req.Header.From,
		Func:      req.Header.Func,
	}
	res.Code = code
	res.Desc = desc
	res.Data = data
	return res
}