1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 18:50:54 +00:00

code simplify for package middleware

This commit is contained in:
fuxiaohei 2015-02-23 11:50:13 +08:00
parent 77c1109134
commit 2ed272aeb2
2 changed files with 15 additions and 15 deletions

View File

@ -323,7 +323,7 @@ func Exception(errcode string, w http.ResponseWriter, r *http.Request, msg strin
w.WriteHeader(isint) w.WriteHeader(isint)
h(w, r) h(w, r)
return return
} else { }
isint, err := strconv.Atoi(errcode) isint, err := strconv.Atoi(errcode)
if err != nil { if err != nil {
isint = 500 isint = 500
@ -335,5 +335,5 @@ func Exception(errcode string, w http.ResponseWriter, r *http.Request, msg strin
w.WriteHeader(isint) w.WriteHeader(isint)
fmt.Fprintln(w, msg) fmt.Fprintln(w, msg)
return return
}
} }

View File

@ -34,7 +34,6 @@ type Translation struct {
} }
func NewLocale(filepath string, defaultlocal string) *Translation { func NewLocale(filepath string, defaultlocal string) *Translation {
i18n := make(map[string]map[string]string)
file, err := os.Open(filepath) file, err := os.Open(filepath)
if err != nil { if err != nil {
panic("open " + filepath + " err :" + err.Error()) panic("open " + filepath + " err :" + err.Error())
@ -43,8 +42,9 @@ func NewLocale(filepath string, defaultlocal string) *Translation {
if err != nil { if err != nil {
panic("read " + filepath + " err :" + err.Error()) panic("read " + filepath + " err :" + err.Error())
} }
err = json.Unmarshal(data, &i18n)
if err != nil { i18n := make(map[string]map[string]string)
if err = json.Unmarshal(data, &i18n); err != nil {
panic("json.Unmarshal " + filepath + " err :" + err.Error()) panic("json.Unmarshal " + filepath + " err :" + err.Error())
} }
return &Translation{ return &Translation{