diff --git a/main.go b/main.go index 53aece1..28f6143 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "flag" "fmt" "github.com/esrrhs/go-engine/src/geoip" @@ -100,6 +101,23 @@ Usage: func main() { + defer func() { + if r := recover(); r != nil { + var err error + switch x := r.(type) { + case string: + err = errors.New(x) + case error: + err = x + default: + err = errors.New("Unknown panic") + } + if err != nil { + loggo.Error("crash %s", err) + } + } + }() + t := flag.String("type", "", "client or server") listen := flag.String("l", "", "listen addr") target := flag.String("t", "", "target addr")