@@ -18,6 +18,26 @@ type Message struct {
18
18
done bool
19
19
}
20
20
21
+ func NewTextMessage (text string , mimeType string ) * Message {
22
+ return & Message {
23
+ rwer : bytes .NewBufferString (text ),
24
+ mimeType : mimeType ,
25
+ }
26
+ }
27
+
28
+ func NewBinMessage (data []byte , mimeType string ) * Message {
29
+ return & Message {
30
+ rwer : bytes .NewBuffer (data ),
31
+ mimeType : mimeType ,
32
+ }
33
+ }
34
+ func NewFileMessage (u string , mimeType string ) * Message {
35
+ return & Message {
36
+ u : & url.URL {Path : u },
37
+ mimeType : mimeType ,
38
+ }
39
+ }
40
+
21
41
// Mime returns the MIME type of the message
22
42
23
43
func (m * Message ) Mime () string {
@@ -34,6 +54,11 @@ func (m *Message) Read(p []byte) (n int, err error) {
34
54
return m .rwer .Read (p )
35
55
}
36
56
57
+ // ReadFrom implements the io.ReaderFrom interface
58
+ func (m * Message ) ReadFrom (r io.Reader ) (n int64 , err error ) {
59
+ return io .Copy (m .rwer , r )
60
+ }
61
+
37
62
// SetActor sets the actor that sent the message
38
63
func (m * Message ) SetActor (actor Actor ) {
39
64
m .msgActor = actor
@@ -49,6 +74,10 @@ func (m *Message) Write(p []byte) (n int, err error) {
49
74
return m .rwer .Write (p )
50
75
}
51
76
77
+ func (m * Message ) WriteTo (w io.Writer ) (n int64 , err error ) {
78
+ return io .Copy (w , m .rwer )
79
+ }
80
+
52
81
// URL returns the URL of the message message
53
82
func (b * Message ) URL () * url.URL {
54
83
return b .u
@@ -68,7 +97,15 @@ func (m *Message) Done() {
68
97
func (m * Message ) String () string {
69
98
70
99
switch m .mimeType {
71
- case ioutils .MimeTextPlain , ioutils .MimeTextHTML , ioutils .MimeMarkDown , ioutils .MimeTextYAML :
100
+ case ioutils .MimeTextPlain ,
101
+ ioutils .MimeTextHTML ,
102
+ ioutils .MimeMarkDown ,
103
+ ioutils .MimeTextYAML ,
104
+ ioutils .MimeApplicationJSON ,
105
+ ioutils .MimeApplicationXML ,
106
+ ioutils .MimeTextXML ,
107
+ ioutils .MimeTextCSS ,
108
+ ioutils .MimeTextCSV :
72
109
return m .rwer .(* bytes.Buffer ).String ()
73
110
default :
74
111
return fmt .Sprintf ("{mimeType: %s, actor: %s}" , m .mimeType , m .msgActor )
0 commit comments