1
0
Fork 0

Allow []byte, string or anything xml.Marshal'able to be sent.

This commit is contained in:
Matt Goodall 2012-07-06 16:24:32 +01:00
parent 8dcfd43ca7
commit 3eb1c9f722
1 changed files with 20 additions and 2 deletions

View File

@ -63,10 +63,28 @@ func (stream *Stream) UpgradeTLS(config *tls.Config) error {
return nil
}
func (stream *Stream) Send(s string) error {
if _, err := stream.conn.Write([]byte(s)); err != nil {
func (stream *Stream) Send(v interface{}) error {
var bytes []byte
switch v2 := v.(type) {
case []byte:
bytes = v2
case string:
bytes = []byte(v2)
default:
b, err := xml.Marshal(v2)
if err != nil {
return err
}
bytes = b
}
log.Println("send:", string(bytes))
if _, err := stream.conn.Write(bytes); err != nil {
return err
}
return nil
}