-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathutil.go
46 lines (33 loc) · 825 Bytes
/
util.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
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... ))
}