Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenhan wang
pastebin
Commits
b1dc3c45
Commit
b1dc3c45
authored
Feb 26, 2023
by
chenhan wang
Browse files
fix:response format fixed
parent
48db6746
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/app/controller/foo.go
View file @
b1dc3c45
...
@@ -2,6 +2,8 @@ package controller
...
@@ -2,6 +2,8 @@ package controller
import
(
import
(
"backend/model"
"backend/model"
"bytes"
"encoding/json"
"io"
"io"
"math/rand"
"math/rand"
"mime/multipart"
"mime/multipart"
...
@@ -236,3 +238,13 @@ func TypeComplement(typ string) string {
...
@@ -236,3 +238,13 @@ func TypeComplement(typ string) string {
}
}
return
typ
return
typ
}
}
func
myMarshal
(
data
interface
{})
(
string
,
error
)
{
bf
:=
bytes
.
NewBuffer
([]
byte
{})
jsonEncoder
:=
json
.
NewEncoder
(
bf
)
jsonEncoder
.
SetEscapeHTML
(
false
)
if
err
:=
jsonEncoder
.
Encode
(
data
);
err
!=
nil
{
return
""
,
err
}
return
bf
.
String
(),
nil
}
backend/app/controller/handler.go
View file @
b1dc3c45
...
@@ -3,7 +3,6 @@ package controller
...
@@ -3,7 +3,6 @@ package controller
import
(
import
(
"backend/app/response"
"backend/app/response"
"backend/model"
"backend/model"
"encoding/json"
"net/http"
"net/http"
"time"
"time"
...
@@ -74,13 +73,13 @@ func FileUp(c echo.Context) error {
...
@@ -74,13 +73,13 @@ func FileUp(c echo.Context) error {
// 更新数据库
// 更新数据库
_
,
data
.
Url
=
DBupdate
(
c
,
info
)
// 不分配uid
_
,
data
.
Url
=
DBupdate
(
c
,
info
)
// 不分配uid
data
.
Name
=
info
.
Name
data
.
Name
=
info
.
Name
dataj
,
err
:=
json
.
Marshal
(
data
)
dataj
,
err
:=
my
Marshal
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
logrus
.
Println
(
err
)
logrus
.
Println
(
err
)
return
err
return
err
}
}
//return response.SendResponse2(c, http.StatusOK, "文件上传成功", info.TextName, GetTextContentType(info.TextType), url)
//return response.SendResponse2(c, http.StatusOK, "文件上传成功", info.TextName, GetTextContentType(info.TextType), url)
return
response
.
SendResponse
(
c
,
http
.
StatusOK
,
"文件上传成功"
,
string
(
dataj
)
)
return
response
.
SendResponse
(
c
,
http
.
StatusOK
,
"文件上传成功"
,
dataj
)
}
}
/*
/*
...
@@ -115,12 +114,11 @@ func Down(c echo.Context) error {
...
@@ -115,12 +114,11 @@ func Down(c echo.Context) error {
return
response
.
SendResponse
(
c
,
http
.
StatusForbidden
,
cookieMsg
+
"error:密码错误"
,
""
)
//403
return
response
.
SendResponse
(
c
,
http
.
StatusForbidden
,
cookieMsg
+
"error:密码错误"
,
""
)
//403
case
1
:
// 鉴权通过
case
1
:
// 鉴权通过
Data
:=
new
(
Msg
)
Data
:=
new
(
Msg
)
Data
.
Content
=
model
.
Find1
(
info
.
Url
,
"content"
)
// 文件内容
Data
.
Content
=
model
.
Find1
(
info
.
Url
,
"content"
)
// 文件内容
Data
.
Type
=
model
.
Find1
(
info
.
Url
,
"TextType"
)
// 文件类型
Data
.
Type
=
GetFileContentType
(
model
.
Find1
(
info
.
Url
,
"TextType"
))
// 文件类型
Data
.
Type
=
GetFileContentType
(
Data
.
Type
)
Data
.
Name
=
model
.
Find1
(
info
.
Url
,
"TextName"
)
Data
.
Name
=
model
.
Find1
(
info
.
Url
,
"TextName"
)
dataj
,
_
:=
json
.
Marshal
(
Data
)
// 文件名
dataj
,
_
:=
my
Marshal
(
Data
)
// 文件名
return
response
.
SendResponse
(
c
,
http
.
StatusOK
,
cookieMsg
+
"success"
,
string
(
dataj
)
)
// 返回数据
return
response
.
SendResponse
(
c
,
http
.
StatusOK
,
cookieMsg
+
"success"
,
dataj
)
// 返回数据
case
2
:
case
2
:
return
response
.
SendResponse
(
c
,
http
.
StatusGone
,
cookieMsg
+
"error:内容过期"
,
""
)
//410
return
response
.
SendResponse
(
c
,
http
.
StatusGone
,
cookieMsg
+
"error:内容过期"
,
""
)
//410
case
3
:
case
3
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
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 comment