Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
8d7f48ea
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8d7f48ea
编写于
11月 29, 2020
作者:
M
Ming Deng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
expose more error code in web module
上级
4afa9d2d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
74 addition
and
42 deletion
+74
-42
adapter/controller.go
adapter/controller.go
+2
-1
adapter/session/session.go
adapter/session/session.go
+1
-1
client/orm/utils.go
client/orm/utils.go
+2
-2
client/orm/utils_test.go
client/orm/utils_test.go
+1
-1
server/web/context/output.go
server/web/context/output.go
+4
-4
server/web/controller.go
server/web/controller.go
+44
-27
server/web/session/session.go
server/web/session/session.go
+20
-6
未找到文件。
adapter/controller.go
浏览文件 @
8d7f48ea
...
@@ -212,7 +212,8 @@ func (c *Controller) ServeFormatted(encoding ...bool) {
...
@@ -212,7 +212,8 @@ func (c *Controller) ServeFormatted(encoding ...bool) {
// Input returns the input data map from POST or PUT request body and query string.
// Input returns the input data map from POST or PUT request body and query string.
func
(
c
*
Controller
)
Input
()
url
.
Values
{
func
(
c
*
Controller
)
Input
()
url
.
Values
{
return
(
*
web
.
Controller
)(
c
)
.
Input
()
val
,
_
:=
(
*
web
.
Controller
)(
c
)
.
Input
()
return
val
}
}
// ParseForm maps input data map to obj struct.
// ParseForm maps input data map to obj struct.
...
...
adapter/session/session.go
浏览文件 @
8d7f48ea
...
@@ -141,7 +141,7 @@ func (manager *Manager) GC() {
...
@@ -141,7 +141,7 @@ func (manager *Manager) GC() {
// SessionRegenerateID Regenerate a session id for this SessionStore who's id is saving in http request.
// SessionRegenerateID Regenerate a session id for this SessionStore who's id is saving in http request.
func
(
manager
*
Manager
)
SessionRegenerateID
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
Store
{
func
(
manager
*
Manager
)
SessionRegenerateID
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
Store
{
s
:=
(
*
session
.
Manager
)(
manager
)
.
SessionRegenerateID
(
w
,
r
)
s
,
_
:=
(
*
session
.
Manager
)(
manager
)
.
SessionRegenerateID
(
w
,
r
)
return
&
NewToOldStoreAdapter
{
return
&
NewToOldStoreAdapter
{
delegate
:
s
,
delegate
:
s
,
}
}
...
...
client/orm/utils.go
浏览文件 @
8d7f48ea
...
@@ -49,12 +49,12 @@ func (f *StrTo) Set(v string) {
...
@@ -49,12 +49,12 @@ func (f *StrTo) Set(v string) {
// Clear string
// Clear string
func
(
f
*
StrTo
)
Clear
()
{
func
(
f
*
StrTo
)
Clear
()
{
*
f
=
StrTo
(
0x1E
)
*
f
=
StrTo
(
rune
(
0x1E
)
)
}
}
// Exist check string exist
// Exist check string exist
func
(
f
StrTo
)
Exist
()
bool
{
func
(
f
StrTo
)
Exist
()
bool
{
return
string
(
f
)
!=
string
(
0x1E
)
return
string
(
f
)
!=
string
(
rune
(
0x1E
)
)
}
}
// Bool string to bool
// Bool string to bool
...
...
client/orm/utils_test.go
浏览文件 @
8d7f48ea
...
@@ -67,4 +67,4 @@ func TestSnakeStringWithAcronym(t *testing.T) {
...
@@ -67,4 +67,4 @@ func TestSnakeStringWithAcronym(t *testing.T) {
t
.
Error
(
"Unit Test Fail:"
,
v
,
res
,
answer
[
v
])
t
.
Error
(
"Unit Test Fail:"
,
v
,
res
,
answer
[
v
])
}
}
}
}
}
}
\ No newline at end of file
server/web/context/output.go
浏览文件 @
8d7f48ea
...
@@ -261,15 +261,15 @@ func (output *BeegoOutput) XML(data interface{}, hasIndent bool) error {
...
@@ -261,15 +261,15 @@ func (output *BeegoOutput) XML(data interface{}, hasIndent bool) error {
}
}
// ServeFormatted serves YAML, XML or JSON, depending on the value of the Accept header
// ServeFormatted serves YAML, XML or JSON, depending on the value of the Accept header
func
(
output
*
BeegoOutput
)
ServeFormatted
(
data
interface
{},
hasIndent
bool
,
hasEncode
...
bool
)
{
func
(
output
*
BeegoOutput
)
ServeFormatted
(
data
interface
{},
hasIndent
bool
,
hasEncode
...
bool
)
error
{
accept
:=
output
.
Context
.
Input
.
Header
(
"Accept"
)
accept
:=
output
.
Context
.
Input
.
Header
(
"Accept"
)
switch
accept
{
switch
accept
{
case
ApplicationYAML
:
case
ApplicationYAML
:
output
.
YAML
(
data
)
return
output
.
YAML
(
data
)
case
ApplicationXML
,
TextXML
:
case
ApplicationXML
,
TextXML
:
output
.
XML
(
data
,
hasIndent
)
return
output
.
XML
(
data
,
hasIndent
)
default
:
default
:
output
.
JSON
(
data
,
hasIndent
,
len
(
hasEncode
)
>
0
&&
hasEncode
[
0
])
return
output
.
JSON
(
data
,
hasIndent
,
len
(
hasEncode
)
>
0
&&
hasEncode
[
0
])
}
}
}
}
...
...
server/web/controller.go
浏览文件 @
8d7f48ea
...
@@ -16,6 +16,7 @@ package web
...
@@ -16,6 +16,7 @@ package web
import
(
import
(
"bytes"
"bytes"
context2
"context"
"errors"
"errors"
"fmt"
"fmt"
"html/template"
"html/template"
...
@@ -250,13 +251,16 @@ func (c *Controller) Render() error {
...
@@ -250,13 +251,16 @@ func (c *Controller) Render() error {
// RenderString returns the rendered template string. Do not send out response.
// RenderString returns the rendered template string. Do not send out response.
func
(
c
*
Controller
)
RenderString
()
(
string
,
error
)
{
func
(
c
*
Controller
)
RenderString
()
(
string
,
error
)
{
b
,
e
:=
c
.
RenderBytes
()
b
,
e
:=
c
.
RenderBytes
()
if
e
!=
nil
{
return
""
,
e
}
return
string
(
b
),
e
return
string
(
b
),
e
}
}
// RenderBytes returns the bytes of rendered template string. Do not send out response.
// RenderBytes returns the bytes of rendered template string. Do not send out response.
func
(
c
*
Controller
)
RenderBytes
()
([]
byte
,
error
)
{
func
(
c
*
Controller
)
RenderBytes
()
([]
byte
,
error
)
{
buf
,
err
:=
c
.
renderTemplate
()
buf
,
err
:=
c
.
renderTemplate
()
//if the controller has set layout, then first get the tplName's content set the content to the layout
//
if the controller has set layout, then first get the tplName's content set the content to the layout
if
err
==
nil
&&
c
.
Layout
!=
""
{
if
err
==
nil
&&
c
.
Layout
!=
""
{
c
.
Data
[
"LayoutContent"
]
=
template
.
HTML
(
buf
.
String
())
c
.
Data
[
"LayoutContent"
]
=
template
.
HTML
(
buf
.
String
())
...
@@ -276,7 +280,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
...
@@ -276,7 +280,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
}
}
buf
.
Reset
()
buf
.
Reset
()
ExecuteViewPathTemplate
(
&
buf
,
c
.
Layout
,
c
.
viewPath
(),
c
.
Data
)
err
=
ExecuteViewPathTemplate
(
&
buf
,
c
.
Layout
,
c
.
viewPath
(),
c
.
Data
)
}
}
return
buf
.
Bytes
(),
err
return
buf
.
Bytes
(),
err
}
}
...
@@ -373,50 +377,57 @@ func (c *Controller) URLFor(endpoint string, values ...interface{}) string {
...
@@ -373,50 +377,57 @@ func (c *Controller) URLFor(endpoint string, values ...interface{}) string {
}
}
// ServeJSON sends a json response with encoding charset.
// ServeJSON sends a json response with encoding charset.
func
(
c
*
Controller
)
ServeJSON
(
encoding
...
bool
)
{
func
(
c
*
Controller
)
ServeJSON
(
encoding
...
bool
)
error
{
var
(
var
(
hasIndent
=
BConfig
.
RunMode
!=
PROD
hasIndent
=
BConfig
.
RunMode
!=
PROD
hasEncoding
=
len
(
encoding
)
>
0
&&
encoding
[
0
]
hasEncoding
=
len
(
encoding
)
>
0
&&
encoding
[
0
]
)
)
c
.
Ctx
.
Output
.
JSON
(
c
.
Data
[
"json"
],
hasIndent
,
hasEncoding
)
return
c
.
Ctx
.
Output
.
JSON
(
c
.
Data
[
"json"
],
hasIndent
,
hasEncoding
)
}
}
// ServeJSONP sends a jsonp response.
// ServeJSONP sends a jsonp response.
func
(
c
*
Controller
)
ServeJSONP
()
{
func
(
c
*
Controller
)
ServeJSONP
()
error
{
hasIndent
:=
BConfig
.
RunMode
!=
PROD
hasIndent
:=
BConfig
.
RunMode
!=
PROD
c
.
Ctx
.
Output
.
JSONP
(
c
.
Data
[
"jsonp"
],
hasIndent
)
return
c
.
Ctx
.
Output
.
JSONP
(
c
.
Data
[
"jsonp"
],
hasIndent
)
}
}
// ServeXML sends xml response.
// ServeXML sends xml response.
func
(
c
*
Controller
)
ServeXML
()
{
func
(
c
*
Controller
)
ServeXML
()
error
{
hasIndent
:=
BConfig
.
RunMode
!=
PROD
hasIndent
:=
BConfig
.
RunMode
!=
PROD
c
.
Ctx
.
Output
.
XML
(
c
.
Data
[
"xml"
],
hasIndent
)
return
c
.
Ctx
.
Output
.
XML
(
c
.
Data
[
"xml"
],
hasIndent
)
}
}
// ServeYAML sends yaml response.
// ServeYAML sends yaml response.
func
(
c
*
Controller
)
ServeYAML
()
{
func
(
c
*
Controller
)
ServeYAML
()
error
{
c
.
Ctx
.
Output
.
YAML
(
c
.
Data
[
"yaml"
])
return
c
.
Ctx
.
Output
.
YAML
(
c
.
Data
[
"yaml"
])
}
}
// ServeFormatted serve YAML, XML OR JSON, depending on the value of the Accept header
// ServeFormatted serve YAML, XML OR JSON, depending on the value of the Accept header
func
(
c
*
Controller
)
ServeFormatted
(
encoding
...
bool
)
{
func
(
c
*
Controller
)
ServeFormatted
(
encoding
...
bool
)
error
{
hasIndent
:=
BConfig
.
RunMode
!=
PROD
hasIndent
:=
BConfig
.
RunMode
!=
PROD
hasEncoding
:=
len
(
encoding
)
>
0
&&
encoding
[
0
]
hasEncoding
:=
len
(
encoding
)
>
0
&&
encoding
[
0
]
c
.
Ctx
.
Output
.
ServeFormatted
(
c
.
Data
,
hasIndent
,
hasEncoding
)
return
c
.
Ctx
.
Output
.
ServeFormatted
(
c
.
Data
,
hasIndent
,
hasEncoding
)
}
}
// Input returns the input data map from POST or PUT request body and query string.
// Input returns the input data map from POST or PUT request body and query string.
func
(
c
*
Controller
)
Input
()
url
.
Values
{
func
(
c
*
Controller
)
Input
()
(
url
.
Values
,
error
)
{
if
c
.
Ctx
.
Request
.
Form
==
nil
{
if
c
.
Ctx
.
Request
.
Form
==
nil
{
c
.
Ctx
.
Request
.
ParseForm
()
err
:=
c
.
Ctx
.
Request
.
ParseForm
()
if
err
!=
nil
{
return
nil
,
err
}
}
}
return
c
.
Ctx
.
Request
.
Form
return
c
.
Ctx
.
Request
.
Form
,
nil
}
}
// ParseForm maps input data map to obj struct.
// ParseForm maps input data map to obj struct.
func
(
c
*
Controller
)
ParseForm
(
obj
interface
{})
error
{
func
(
c
*
Controller
)
ParseForm
(
obj
interface
{})
error
{
return
ParseForm
(
c
.
Input
(),
obj
)
form
,
err
:=
c
.
Input
()
if
err
!=
nil
{
return
err
}
return
ParseForm
(
form
,
obj
)
}
}
// GetString returns the input value by key string or the default value while it's present and input is blank
// GetString returns the input value by key string or the default value while it's present and input is blank
...
@@ -438,7 +449,7 @@ func (c *Controller) GetStrings(key string, def ...[]string) []string {
...
@@ -438,7 +449,7 @@ func (c *Controller) GetStrings(key string, def ...[]string) []string {
defv
=
def
[
0
]
defv
=
def
[
0
]
}
}
if
f
:=
c
.
Input
();
f
=
=
nil
{
if
f
,
err
:=
c
.
Input
();
f
==
nil
||
err
!
=
nil
{
return
defv
return
defv
}
else
if
vs
:=
f
[
key
];
len
(
vs
)
>
0
{
}
else
if
vs
:=
f
[
key
];
len
(
vs
)
>
0
{
return
vs
return
vs
...
@@ -618,11 +629,11 @@ func (c *Controller) StartSession() session.Store {
...
@@ -618,11 +629,11 @@ func (c *Controller) StartSession() session.Store {
}
}
// SetSession puts value into session.
// SetSession puts value into session.
func
(
c
*
Controller
)
SetSession
(
name
interface
{},
value
interface
{})
{
func
(
c
*
Controller
)
SetSession
(
name
interface
{},
value
interface
{})
error
{
if
c
.
CruSession
==
nil
{
if
c
.
CruSession
==
nil
{
c
.
StartSession
()
c
.
StartSession
()
}
}
c
.
CruSession
.
Set
(
nil
,
name
,
value
)
return
c
.
CruSession
.
Set
(
context2
.
Background
()
,
name
,
value
)
}
}
// GetSession gets value from session.
// GetSession gets value from session.
...
@@ -630,32 +641,38 @@ func (c *Controller) GetSession(name interface{}) interface{} {
...
@@ -630,32 +641,38 @@ func (c *Controller) GetSession(name interface{}) interface{} {
if
c
.
CruSession
==
nil
{
if
c
.
CruSession
==
nil
{
c
.
StartSession
()
c
.
StartSession
()
}
}
return
c
.
CruSession
.
Get
(
nil
,
name
)
return
c
.
CruSession
.
Get
(
context2
.
Background
()
,
name
)
}
}
// DelSession removes value from session.
// DelSession removes value from session.
func
(
c
*
Controller
)
DelSession
(
name
interface
{})
{
func
(
c
*
Controller
)
DelSession
(
name
interface
{})
error
{
if
c
.
CruSession
==
nil
{
if
c
.
CruSession
==
nil
{
c
.
StartSession
()
c
.
StartSession
()
}
}
c
.
CruSession
.
Delete
(
nil
,
name
)
return
c
.
CruSession
.
Delete
(
context2
.
Background
()
,
name
)
}
}
// SessionRegenerateID regenerates session id for this session.
// SessionRegenerateID regenerates session id for this session.
// the session data have no changes.
// the session data have no changes.
func
(
c
*
Controller
)
SessionRegenerateID
()
{
func
(
c
*
Controller
)
SessionRegenerateID
()
error
{
if
c
.
CruSession
!=
nil
{
if
c
.
CruSession
!=
nil
{
c
.
CruSession
.
SessionRelease
(
nil
,
c
.
Ctx
.
ResponseWriter
)
c
.
CruSession
.
SessionRelease
(
context2
.
Background
()
,
c
.
Ctx
.
ResponseWriter
)
}
}
c
.
CruSession
=
GlobalSessions
.
SessionRegenerateID
(
c
.
Ctx
.
ResponseWriter
,
c
.
Ctx
.
Request
)
var
err
error
c
.
CruSession
,
err
=
GlobalSessions
.
SessionRegenerateID
(
c
.
Ctx
.
ResponseWriter
,
c
.
Ctx
.
Request
)
c
.
Ctx
.
Input
.
CruSession
=
c
.
CruSession
c
.
Ctx
.
Input
.
CruSession
=
c
.
CruSession
return
err
}
}
// DestroySession cleans session data and session cookie.
// DestroySession cleans session data and session cookie.
func
(
c
*
Controller
)
DestroySession
()
{
func
(
c
*
Controller
)
DestroySession
()
error
{
c
.
Ctx
.
Input
.
CruSession
.
Flush
(
nil
)
err
:=
c
.
Ctx
.
Input
.
CruSession
.
Flush
(
nil
)
if
err
!=
nil
{
return
err
}
c
.
Ctx
.
Input
.
CruSession
=
nil
c
.
Ctx
.
Input
.
CruSession
=
nil
GlobalSessions
.
SessionDestroy
(
c
.
Ctx
.
ResponseWriter
,
c
.
Ctx
.
Request
)
GlobalSessions
.
SessionDestroy
(
c
.
Ctx
.
ResponseWriter
,
c
.
Ctx
.
Request
)
return
nil
}
}
// IsAjax returns this request is ajax or not.
// IsAjax returns this request is ajax or not.
...
...
server/web/session/session.go
浏览文件 @
8d7f48ea
...
@@ -298,15 +298,21 @@ func (manager *Manager) GC() {
...
@@ -298,15 +298,21 @@ func (manager *Manager) GC() {
}
}
// SessionRegenerateID Regenerate a session id for this SessionStore who's id is saving in http request.
// SessionRegenerateID Regenerate a session id for this SessionStore who's id is saving in http request.
func
(
manager
*
Manager
)
SessionRegenerateID
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
session
Store
)
{
func
(
manager
*
Manager
)
SessionRegenerateID
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
Store
,
error
)
{
sid
,
err
:=
manager
.
sessionID
()
sid
,
err
:=
manager
.
sessionID
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
nil
,
err
}
}
var
session
Store
cookie
,
err
:=
r
.
Cookie
(
manager
.
config
.
CookieName
)
cookie
,
err
:=
r
.
Cookie
(
manager
.
config
.
CookieName
)
if
err
!=
nil
||
cookie
.
Value
==
""
{
if
err
!=
nil
||
cookie
.
Value
==
""
{
//delete old cookie
//delete old cookie
session
,
_
=
manager
.
provider
.
SessionRead
(
nil
,
sid
)
session
,
err
=
manager
.
provider
.
SessionRead
(
nil
,
sid
)
if
err
!=
nil
{
return
nil
,
err
}
cookie
=
&
http
.
Cookie
{
Name
:
manager
.
config
.
CookieName
,
cookie
=
&
http
.
Cookie
{
Name
:
manager
.
config
.
CookieName
,
Value
:
url
.
QueryEscape
(
sid
),
Value
:
url
.
QueryEscape
(
sid
),
Path
:
"/"
,
Path
:
"/"
,
...
@@ -315,8 +321,16 @@ func (manager *Manager) SessionRegenerateID(w http.ResponseWriter, r *http.Reque
...
@@ -315,8 +321,16 @@ func (manager *Manager) SessionRegenerateID(w http.ResponseWriter, r *http.Reque
Domain
:
manager
.
config
.
Domain
,
Domain
:
manager
.
config
.
Domain
,
}
}
}
else
{
}
else
{
oldsid
,
_
:=
url
.
QueryUnescape
(
cookie
.
Value
)
oldsid
,
err
:=
url
.
QueryUnescape
(
cookie
.
Value
)
session
,
_
=
manager
.
provider
.
SessionRegenerate
(
nil
,
oldsid
,
sid
)
if
err
!=
nil
{
return
nil
,
err
}
session
,
err
=
manager
.
provider
.
SessionRegenerate
(
nil
,
oldsid
,
sid
)
if
err
!=
nil
{
return
nil
,
err
}
cookie
.
Value
=
url
.
QueryEscape
(
sid
)
cookie
.
Value
=
url
.
QueryEscape
(
sid
)
cookie
.
HttpOnly
=
true
cookie
.
HttpOnly
=
true
cookie
.
Path
=
"/"
cookie
.
Path
=
"/"
...
@@ -335,7 +349,7 @@ func (manager *Manager) SessionRegenerateID(w http.ResponseWriter, r *http.Reque
...
@@ -335,7 +349,7 @@ func (manager *Manager) SessionRegenerateID(w http.ResponseWriter, r *http.Reque
w
.
Header
()
.
Set
(
manager
.
config
.
SessionNameInHTTPHeader
,
sid
)
w
.
Header
()
.
Set
(
manager
.
config
.
SessionNameInHTTPHeader
,
sid
)
}
}
return
return
session
,
nil
}
}
// GetActiveSession Get all active sessions count number.
// GetActiveSession Get all active sessions count number.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录