code simplify for package middleware
Showing
2 changed files
with
15 additions
and
15 deletions
| ... | @@ -323,17 +323,17 @@ func Exception(errcode string, w http.ResponseWriter, r *http.Request, msg strin | ... | @@ -323,17 +323,17 @@ func Exception(errcode string, w http.ResponseWriter, r *http.Request, msg strin |
| 323 | w.WriteHeader(isint) | 323 | w.WriteHeader(isint) |
| 324 | h(w, r) | 324 | h(w, r) |
| 325 | return | 325 | return |
| 326 | } else { | ||
| 327 | isint, err := strconv.Atoi(errcode) | ||
| 328 | if err != nil { | ||
| 329 | isint = 500 | ||
| 330 | } | ||
| 331 | if isint == 404 { | ||
| 332 | msg = "404 page not found" | ||
| 333 | } | ||
| 334 | w.Header().Set("Content-Type", "text/plain; charset=utf-8") | ||
| 335 | w.WriteHeader(isint) | ||
| 336 | fmt.Fprintln(w, msg) | ||
| 337 | return | ||
| 338 | } | 326 | } |
| 327 | isint, err := strconv.Atoi(errcode) | ||
| 328 | if err != nil { | ||
| 329 | isint = 500 | ||
| 330 | } | ||
| 331 | if isint == 404 { | ||
| 332 | msg = "404 page not found" | ||
| 333 | } | ||
| 334 | w.Header().Set("Content-Type", "text/plain; charset=utf-8") | ||
| 335 | w.WriteHeader(isint) | ||
| 336 | fmt.Fprintln(w, msg) | ||
| 337 | return | ||
| 338 | |||
| 339 | } | 339 | } | ... | ... |
| ... | @@ -34,7 +34,6 @@ type Translation struct { | ... | @@ -34,7 +34,6 @@ type Translation struct { |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | func NewLocale(filepath string, defaultlocal string) *Translation { | 36 | func NewLocale(filepath string, defaultlocal string) *Translation { |
| 37 | i18n := make(map[string]map[string]string) | ||
| 38 | file, err := os.Open(filepath) | 37 | file, err := os.Open(filepath) |
| 39 | if err != nil { | 38 | if err != nil { |
| 40 | panic("open " + filepath + " err :" + err.Error()) | 39 | panic("open " + filepath + " err :" + err.Error()) |
| ... | @@ -43,8 +42,9 @@ func NewLocale(filepath string, defaultlocal string) *Translation { | ... | @@ -43,8 +42,9 @@ func NewLocale(filepath string, defaultlocal string) *Translation { |
| 43 | if err != nil { | 42 | if err != nil { |
| 44 | panic("read " + filepath + " err :" + err.Error()) | 43 | panic("read " + filepath + " err :" + err.Error()) |
| 45 | } | 44 | } |
| 46 | err = json.Unmarshal(data, &i18n) | 45 | |
| 47 | if err != nil { | 46 | i18n := make(map[string]map[string]string) |
| 47 | if err = json.Unmarshal(data, &i18n); err != nil { | ||
| 48 | panic("json.Unmarshal " + filepath + " err :" + err.Error()) | 48 | panic("json.Unmarshal " + filepath + " err :" + err.Error()) |
| 49 | } | 49 | } |
| 50 | return &Translation{ | 50 | return &Translation{ | ... | ... |
-
Please register or sign in to post a comment