forked from goshawkdb/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
42 lines (33 loc) · 735 Bytes
/
utils.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
package server
import (
"bytes"
capn "github.com/glycerine/go-capnproto"
"log"
)
func CheckFatal(e error) {
if e != nil {
log.Fatal(e)
}
}
func CheckWarn(e error) bool {
if e != nil {
log.Println("Warning:", e)
return true
}
return false
}
type LogFunc func(...interface{})
var Log LogFunc = LogFunc(func(elems ...interface{}) {})
func SegToBytes(seg *capn.Segment) []byte {
if seg == nil {
log.Fatal("SegToBytes called with nil segment!")
}
buf := new(bytes.Buffer)
if _, err := seg.WriteTo(buf); err != nil {
log.Fatal("Error when writing segment to bytes:", err)
}
return buf.Bytes()
}
type EmptyStruct struct{}
var EmptyStructVal = EmptyStruct{}
func (es EmptyStruct) String() string { return "" }