From 2ed272aeb27cef6f73b8a9e78df409334c61b419 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Mon, 23 Feb 2015 11:50:13 +0800 Subject: [PATCH] code simplify for package middleware --- middleware/error.go | 24 ++++++++++++------------ middleware/i18n.go | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/middleware/error.go b/middleware/error.go index 052e977c..16553543 100644 --- a/middleware/error.go +++ b/middleware/error.go @@ -323,17 +323,17 @@ func Exception(errcode string, w http.ResponseWriter, r *http.Request, msg strin w.WriteHeader(isint) h(w, r) return - } else { - isint, err := strconv.Atoi(errcode) - if err != nil { - isint = 500 - } - if isint == 404 { - msg = "404 page not found" - } - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(isint) - fmt.Fprintln(w, msg) - return } + isint, err := strconv.Atoi(errcode) + if err != nil { + isint = 500 + } + if isint == 404 { + msg = "404 page not found" + } + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.WriteHeader(isint) + fmt.Fprintln(w, msg) + return + } diff --git a/middleware/i18n.go b/middleware/i18n.go index e4dab693..f54b4bb5 100644 --- a/middleware/i18n.go +++ b/middleware/i18n.go @@ -34,7 +34,6 @@ type Translation struct { } func NewLocale(filepath string, defaultlocal string) *Translation { - i18n := make(map[string]map[string]string) file, err := os.Open(filepath) if err != nil { panic("open " + filepath + " err :" + err.Error()) @@ -43,8 +42,9 @@ func NewLocale(filepath string, defaultlocal string) *Translation { if err != nil { 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()) } return &Translation{