forked from sdgdsffdsfff/cat.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta.go
85 lines (73 loc) · 1.4 KB
/
meta.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package cat
import "time"
import "bytes"
import "fmt"
type Meta interface {
SetStatus(Panic)
AddData(string, string)
GetType() string
GetName() string
GetStatus() string
GetTimestamp() time.Time
SetData([]byte)
GetData() []byte
}
type meta struct {
m_type string
m_name string
m_status string
m_timestamp time.Time
m_data *bytes.Buffer
}
func NewMeta(t string, n string) Meta {
return &meta{
m_type: t,
m_name: n,
m_status: "unset",
m_timestamp: time.Now(),
m_data: nil,
}
}
func (m *meta) SetStatus(err Panic) {
if err == nil {
m.m_status = "0"
} else {
m.m_status = fmt.Sprintf("%v", err)
}
}
func (m *meta) AddData(key string, value string) {
if m.m_data == nil {
m.m_data = new(bytes.Buffer)
m.m_data.WriteString(key)
m.m_data.WriteString("=")
m.m_data.WriteString(value)
} else {
m.m_data.WriteString("&")
m.m_data.WriteString(key)
m.m_data.WriteString("=")
m.m_data.WriteString(value)
}
}
func (m *meta) GetType() string {
return m.m_type
}
func (m *meta) GetName() string {
return m.m_name
}
func (m *meta) GetStatus() string {
return m.m_status
}
func (m *meta) GetTimestamp() time.Time {
return m.m_timestamp
}
func (m *meta) SetData(data []byte) {
m.m_data = new(bytes.Buffer)
m.m_data.Write(data)
}
func (m *meta) GetData() []byte {
if m.m_data != nil {
return m.m_data.Bytes()
} else {
return make([]byte, 0)
}
}