Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
2ed272ae
authored
2015-02-23 11:50:13 +0800
by
fuxiaohei
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
code simplify for package middleware
1 parent
77c11091
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
15 deletions
middleware/error.go
middleware/i18n.go
middleware/error.go
View file @
2ed272a
...
...
@@ -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
}
...
...
middleware/i18n.go
View file @
2ed272a
...
...
@@ -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
{
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment