Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (33 sloc) 825 Bytes
package xmpp
import (
"bytes"
"fmt"
"io"
"os"
)
func read(in io.Reader) (string, os.Error) {
buf := make([]byte, 2048)
_, err := in.Read(buf)
return bytes.NewBuffer(buf).String(), err
}
func mustRead(in io.Reader) (out string) {
var err os.Error
if out, err = read(in); err != nil {
die("Failed to read (%s)", err)
}
return
}
func write(out io.Writer, format string, args ...interface{}) int {
buf := bytes.NewBufferString(fmt.Sprintf(format + "\n", args...))
n, err := out.Write(buf.Bytes())
if err != nil {
die("Failed to write to %s (%s)", out, err)
}
return n
}
func die(format string, args ...interface{}) {
panic(os.NewError(fmt.Sprintf(format, args...)))
}
func log(format string, args ...interface{}) {
fmt.Printf("LOG: %s\n", fmt.Sprintf(format, args... ))
}