mirror of
https://github.com/astaxie/beego.git
synced 2025-07-11 22:21:02 +00:00
Compare commits
9 Commits
develop
...
develop-1.
Author | SHA1 | Date | |
---|---|---|---|
3b6d634f55 | |||
d0847e866e | |||
19e6ba8e7c | |||
5fddd26069 | |||
89d4c9a3df | |||
db6af39bcd | |||
9418b243d0 | |||
3d93903f9e | |||
2781f88173 |
@ -255,7 +255,7 @@ func (c *Controller) RenderString() (string, error) {
|
|||||||
// 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())
|
||||||
|
|
||||||
@ -642,12 +642,13 @@ func (c *Controller) DelSession(name interface{}) {
|
|||||||
|
|
||||||
// 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() (err error) {
|
||||||
if c.CruSession != nil {
|
if c.CruSession != nil {
|
||||||
c.CruSession.SessionRelease(c.Ctx.ResponseWriter)
|
c.CruSession.SessionRelease(c.Ctx.ResponseWriter)
|
||||||
}
|
}
|
||||||
c.CruSession = GlobalSessions.SessionRegenerateID(c.Ctx.ResponseWriter, c.Ctx.Request)
|
c.CruSession, err = GlobalSessions.SessionRegenerateID(c.Ctx.ResponseWriter, c.Ctx.Request)
|
||||||
c.Ctx.Input.CruSession = c.CruSession
|
c.Ctx.Input.CruSession = c.CruSession
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// DestroySession cleans session data and session cookie.
|
// DestroySession cleans session data and session cookie.
|
||||||
|
@ -37,7 +37,7 @@ func PrometheusMiddleWare(next http.Handler) http.Handler {
|
|||||||
"appname": beego.BConfig.AppName,
|
"appname": beego.BConfig.AppName,
|
||||||
},
|
},
|
||||||
Help: "The statics info for http request",
|
Help: "The statics info for http request",
|
||||||
}, []string{"pattern", "method", "status", "duration"})
|
}, []string{"pattern", "method", "status"})
|
||||||
|
|
||||||
prometheus.MustRegister(summaryVec)
|
prometheus.MustRegister(summaryVec)
|
||||||
|
|
||||||
@ -95,5 +95,5 @@ func report(dur time.Duration, writer http.ResponseWriter, q *http.Request, vec
|
|||||||
logs.Warn("we can not find the router info for this request, so request will be recorded as UNKNOWN: " + q.URL.String())
|
logs.Warn("we can not find the router info for this request, so request will be recorded as UNKNOWN: " + q.URL.String())
|
||||||
}
|
}
|
||||||
ms := dur / time.Millisecond
|
ms := dur / time.Millisecond
|
||||||
vec.WithLabelValues(ptn, q.Method, strconv.Itoa(status), strconv.Itoa(int(ms))).Observe(float64(ms))
|
vec.WithLabelValues(ptn, q.Method, strconv.Itoa(status)).Observe(float64(ms))
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func TestPrometheusMiddleWare(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
}
|
}
|
||||||
vec := prometheus.NewSummaryVec(prometheus.SummaryOpts{}, []string{"pattern", "method", "status", "duration"})
|
vec := prometheus.NewSummaryVec(prometheus.SummaryOpts{}, []string{"pattern", "method", "status"})
|
||||||
|
|
||||||
report(time.Second, writer, request, vec)
|
report(time.Second, writer, request, vec)
|
||||||
middleware.ServeHTTP(writer, request)
|
middleware.ServeHTTP(writer, request)
|
||||||
|
13
parser.go
13
parser.go
@ -49,7 +49,6 @@ func init() {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
lastupdateFilename = "lastupdate.tmp"
|
lastupdateFilename = "lastupdate.tmp"
|
||||||
commentFilename string
|
|
||||||
pkgLastupdate map[string]int64
|
pkgLastupdate map[string]int64
|
||||||
genInfoList map[string][]ControllerComments
|
genInfoList map[string][]ControllerComments
|
||||||
|
|
||||||
@ -70,16 +69,13 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const commentPrefix = "commentsRouter_"
|
const commentFilename = "commentsRouter.go"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pkgLastupdate = make(map[string]int64)
|
pkgLastupdate = make(map[string]int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parserPkg(pkgRealpath, pkgpath string) error {
|
func parserPkg(pkgRealpath, pkgpath string) error {
|
||||||
rep := strings.NewReplacer("\\", "_", "/", "_", ".", "_")
|
|
||||||
commentFilename, _ = filepath.Rel(AppPath, pkgRealpath)
|
|
||||||
commentFilename = commentPrefix + rep.Replace(commentFilename) + ".go"
|
|
||||||
if !compareFile(pkgRealpath) {
|
if !compareFile(pkgRealpath) {
|
||||||
logs.Info(pkgRealpath + " no changed")
|
logs.Info(pkgRealpath + " no changed")
|
||||||
return nil
|
return nil
|
||||||
@ -102,7 +98,10 @@ func parserPkg(pkgRealpath, pkgpath string) error {
|
|||||||
if specDecl.Recv != nil {
|
if specDecl.Recv != nil {
|
||||||
exp, ok := specDecl.Recv.List[0].Type.(*ast.StarExpr) // Check that the type is correct first beforing throwing to parser
|
exp, ok := specDecl.Recv.List[0].Type.(*ast.StarExpr) // Check that the type is correct first beforing throwing to parser
|
||||||
if ok {
|
if ok {
|
||||||
parserComments(specDecl, fmt.Sprint(exp.X), pkgpath)
|
err = parserComments(specDecl, fmt.Sprint(exp.X), pkgpath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -500,7 +499,7 @@ func genRouterCode(pkgRealpath string) {
|
|||||||
beego.GlobalControllerRouter["` + k + `"] = append(beego.GlobalControllerRouter["` + k + `"],
|
beego.GlobalControllerRouter["` + k + `"] = append(beego.GlobalControllerRouter["` + k + `"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "` + strings.TrimSpace(c.Method) + `",
|
Method: "` + strings.TrimSpace(c.Method) + `",
|
||||||
` + `Router: "` + c.Router + `"` + `,
|
` + "Router: `" + c.Router + "`" + `,
|
||||||
AllowHTTPMethods: ` + allmethod + `,
|
AllowHTTPMethods: ` + allmethod + `,
|
||||||
MethodParams: ` + methodParams + `,
|
MethodParams: ` + methodParams + `,
|
||||||
Filters: ` + filters + `,
|
Filters: ` + filters + `,
|
||||||
|
@ -295,15 +295,19 @@ 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(sid)
|
session, err = manager.provider.SessionRead(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: "/",
|
||||||
@ -313,8 +317,14 @@ func (manager *Manager) SessionRegenerateID(w http.ResponseWriter, r *http.Reque
|
|||||||
SameSite: manager.config.CookieSameSite,
|
SameSite: manager.config.CookieSameSite,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oldsid, _ := url.QueryUnescape(cookie.Value)
|
oldsid, err := url.QueryUnescape(cookie.Value)
|
||||||
session, _ = manager.provider.SessionRegenerate(oldsid, sid)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
session, err = manager.provider.SessionRegenerate(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 = "/"
|
||||||
@ -333,7 +343,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.
|
||||||
|
2
tree.go
2
tree.go
@ -341,7 +341,7 @@ func (t *Tree) match(treePattern string, pattern string, wildcardValues []string
|
|||||||
if runObject == nil && len(t.fixrouters) > 0 {
|
if runObject == nil && len(t.fixrouters) > 0 {
|
||||||
// Filter the .json .xml .html extension
|
// Filter the .json .xml .html extension
|
||||||
for _, str := range allowSuffixExt {
|
for _, str := range allowSuffixExt {
|
||||||
if strings.HasSuffix(seg, str) {
|
if strings.HasSuffix(seg, str) && strings.HasSuffix(treePattern, seg) {
|
||||||
for _, subTree := range t.fixrouters {
|
for _, subTree := range t.fixrouters {
|
||||||
if subTree.prefix == seg[:len(seg)-len(str)] {
|
if subTree.prefix == seg[:len(seg)-len(str)] {
|
||||||
runObject = subTree.match(treePattern, pattern, wildcardValues, ctx)
|
runObject = subTree.match(treePattern, pattern, wildcardValues, ctx)
|
||||||
|
Reference in New Issue
Block a user