From 3e3ced70d44e104204ddbf804c2af39424cf1245 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Mon, 23 Mar 2015 05:50:10 +0100 Subject: [PATCH] Using log.Panic instead --- auth.go | 5 +++-- binding/binding.go | 3 ++- context.go | 8 ++++---- mode.go | 2 +- recovery_test.go | 4 ++-- utils.go | 5 +++-- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/auth.go b/auth.go index 0cf64e59..648b75ea 100644 --- a/auth.go +++ b/auth.go @@ -9,6 +9,7 @@ import ( "encoding/base64" "errors" "fmt" + "log" "sort" ) @@ -60,12 +61,12 @@ func BasicAuth(accounts Accounts) HandlerFunc { func processAccounts(accounts Accounts) authPairs { if len(accounts) == 0 { - panic("Empty list of authorized credentials") + log.Panic("Empty list of authorized credentials") } pairs := make(authPairs, 0, len(accounts)) for user, password := range accounts { if len(user) == 0 { - panic("User can not be empty") + log.Panic("User can not be empty") } base := user + ":" + password value := "Basic " + base64.StdEncoding.EncodeToString([]byte(base)) diff --git a/binding/binding.go b/binding/binding.go index 752c9129..b0f561a5 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -8,6 +8,7 @@ import ( "encoding/json" "encoding/xml" "errors" + "log" "net/http" "reflect" "strconv" @@ -203,7 +204,7 @@ func setWithProperType(valueKind reflect.Kind, val string, structField reflect.V // https://github.com/codegangsta/martini-contrib/pull/34#issuecomment-29683659 func ensureNotPointer(obj interface{}) { if reflect.TypeOf(obj).Kind() == reflect.Ptr { - panic("Pointers are not accepted as binding models") + log.Panic("Pointers are not accepted as binding models") } } diff --git a/context.go b/context.go index ffd02b8e..d9a7ab1a 100644 --- a/context.go +++ b/context.go @@ -195,7 +195,7 @@ func (c *Context) Get(key string) (interface{}, error) { func (c *Context) MustGet(key string) interface{} { value, err := c.Get(key) if err != nil { - log.Panicf(err.Error()) + log.Panic(err.Error()) } return value } @@ -208,7 +208,7 @@ func ipInMasks(ip net.IP, masks []interface{}) bool { switch t := proxy.(type) { case string: if _, mask, err = net.ParseCIDR(t); err != nil { - panic(err) + log.Panic(err) } case net.IP: mask = &net.IPNet{IP: t, Mask: net.CIDRMask(len(t)*8, len(t)*8)} @@ -402,7 +402,7 @@ func (c *Context) Negotiate(code int, config Negotiate) { case MIMEHTML: data := chooseData(config.HTMLData, config.Data) if len(config.HTMLPath) == 0 { - panic("negotiate config is wrong. html path is needed") + log.Panic("negotiate config is wrong. html path is needed") } c.HTML(code, config.HTMLPath, data) @@ -417,7 +417,7 @@ func (c *Context) Negotiate(code int, config Negotiate) { func (c *Context) NegotiateFormat(offered ...string) string { if len(offered) == 0 { - panic("you must provide at least one offer") + log.Panic("you must provide at least one offer") } if c.accepted == nil { c.accepted = parseAccept(c.Request.Header.Get("Accept")) diff --git a/mode.go b/mode.go index 68b0d1c2..59c8d506 100644 --- a/mode.go +++ b/mode.go @@ -43,7 +43,7 @@ func SetMode(value string) { case TestMode: gin_mode = testCode default: - panic("gin mode unknown: " + value) + log.Panic("gin mode unknown: " + value) } mode_name = value } diff --git a/recovery_test.go b/recovery_test.go index 807146f3..c1ba616f 100644 --- a/recovery_test.go +++ b/recovery_test.go @@ -18,7 +18,7 @@ func TestPanicInHandler(t *testing.T) { r := New() r.Use(Recovery()) r.GET("/recovery", func(_ *Context) { - panic("Oupps, Houston, we have a problem") + log.Panic("Oupps, Houston, we have a problem") }) // RUN @@ -40,7 +40,7 @@ func TestPanicWithAbort(t *testing.T) { r.Use(Recovery()) r.GET("/recovery", func(c *Context) { c.AbortWithStatus(400) - panic("Oupps, Houston, we have a problem") + log.Panic("Oupps, Houston, we have a problem") }) // RUN diff --git a/utils.go b/utils.go index 1fc0d70f..fee39910 100644 --- a/utils.go +++ b/utils.go @@ -6,6 +6,7 @@ package gin import ( "encoding/xml" + "log" "reflect" "runtime" "strings" @@ -49,7 +50,7 @@ func filterFlags(content string) string { func chooseData(custom, wildcard interface{}) interface{} { if custom == nil { if wildcard == nil { - panic("negotiation config is invalid") + log.Panic("negotiation config is invalid") } return wildcard } @@ -71,7 +72,7 @@ func parseAccept(acceptHeader string) (parts []string) { func lastChar(str string) uint8 { size := len(str) if size == 0 { - panic("The length of the string can't be 0") + log.Panic("The length of the string can't be 0") } return str[size-1] }