PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/src/pkg/common/errors.go

https://code.google.com/p/gomemcached/
Go | 41 lines | 34 code | 7 blank | 0 comment | 5 complexity | 12c6a059dfb6d346021ad03a5da994b7 MD5 | raw file
 1package common
 2
 3import (
 4	"os"
 5	"log"
 6	"flag"
 7)
 8
 9var debug = flag.Bool("d", true, "print additional debug output")
10
11func Traceln(v ...interface{}) {
12	if *debug {
13		log.Println(v...)
14	}
15}
16
17func SafelyDo(fname string, f func()) {
18	defer func() {
19		if err := recover(); err != nil {
20			log.Printf("Goroutine %s terminated: %v\n", fname, err)
21		}
22	}()
23	f()
24}
25
26func test(f func(string, ...interface{}),
27err os.Error, msg string) {
28	if err != nil {
29		f("Fail: %s\n%v\n", msg, err)
30		return
31	}
32	Traceln("Ok:", msg)
33}
34
35func Testp(err os.Error, msg string) {
36	test(log.Panicf, err, msg)
37}
38
39func Teste(err os.Error, msg string) {
40	test(log.Fatalf, err, msg)
41}