Skip to content

Commit

Permalink
Using log.Panic instead
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Mar 23, 2015
1 parent 34b1d02 commit 3e3ced7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"log"
"sort"
)

Expand Down Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"encoding/xml"
"errors"
"log"
"net/http"
"reflect"
"strconv"
Expand Down Expand Up @@ -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")
}
}

Expand Down
8 changes: 4 additions & 4 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)}
Expand Down Expand Up @@ -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)

Expand All @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package gin

import (
"encoding/xml"
"log"
"reflect"
"runtime"
"strings"
Expand Down Expand Up @@ -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
}
Expand All @@ -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]
}
Expand Down

0 comments on commit 3e3ced7

Please sign in to comment.