1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 19:50:56 +00:00

Merge branch 'develop' of https://github.com/astaxie/beego into develop

This commit is contained in:
astaxie 2018-07-20 22:30:25 +08:00
commit 81f69f12ab
4 changed files with 36 additions and 12 deletions

View File

@ -76,6 +76,18 @@ func adminIndex(rw http.ResponseWriter, r *http.Request) {
func qpsIndex(rw http.ResponseWriter, r *http.Request) { func qpsIndex(rw http.ResponseWriter, r *http.Request) {
data := make(map[interface{}]interface{}) data := make(map[interface{}]interface{})
data["Content"] = toolbox.StatisticsMap.GetMap() data["Content"] = toolbox.StatisticsMap.GetMap()
// do html escape before display path, avoid xss
if content, ok := (data["Content"]).(map[string]interface{}); ok {
if resultLists, ok := (content["Data"]).([][]string); ok {
for i := range resultLists {
if len(resultLists[i]) > 0 {
resultLists[i][0] = template.HTMLEscapeString(resultLists[i][0])
}
}
}
}
execTpl(rw, data, qpsTpl, defaultScriptsTpl) execTpl(rw, data, qpsTpl, defaultScriptsTpl)
} }

View File

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -167,6 +168,10 @@ func (w *fileLogWriter) createLogFile() (*os.File, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
filepath := path.Dir(w.Filename)
os.MkdirAll(filepath, os.FileMode(perm))
fd, err := os.OpenFile(w.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(perm)) fd, err := os.OpenFile(w.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(perm))
if err == nil { if err == nil {
// Make sure file perm is user set perm cause of `os.OpenFile` will obey umask // Make sure file perm is user set perm cause of `os.OpenFile` will obey umask

View File

@ -86,7 +86,7 @@ func (e *BooleanField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := StrTo(d).Bool() v, err := StrTo(d).Bool()
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err return err
@ -191,7 +191,7 @@ func (e *TimeField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := timeParse(d, formatTime) v, err := timeParse(d, formatTime)
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err return err
@ -250,7 +250,7 @@ func (e *DateField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := timeParse(d, formatDate) v, err := timeParse(d, formatDate)
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err return err
@ -300,7 +300,7 @@ func (e *DateTimeField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := timeParse(d, formatDateTime) v, err := timeParse(d, formatDateTime)
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err return err
@ -350,9 +350,10 @@ func (e *FloatField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := StrTo(d).Float64() v, err := StrTo(d).Float64()
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err
default: default:
return fmt.Errorf("<FloatField.SetRaw> unknown value `%s`", value) return fmt.Errorf("<FloatField.SetRaw> unknown value `%s`", value)
} }
@ -397,9 +398,10 @@ func (e *SmallIntegerField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := StrTo(d).Int16() v, err := StrTo(d).Int16()
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err
default: default:
return fmt.Errorf("<SmallIntegerField.SetRaw> unknown value `%s`", value) return fmt.Errorf("<SmallIntegerField.SetRaw> unknown value `%s`", value)
} }
@ -444,9 +446,10 @@ func (e *IntegerField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := StrTo(d).Int32() v, err := StrTo(d).Int32()
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err
default: default:
return fmt.Errorf("<IntegerField.SetRaw> unknown value `%s`", value) return fmt.Errorf("<IntegerField.SetRaw> unknown value `%s`", value)
} }
@ -491,9 +494,10 @@ func (e *BigIntegerField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := StrTo(d).Int64() v, err := StrTo(d).Int64()
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err
default: default:
return fmt.Errorf("<BigIntegerField.SetRaw> unknown value `%s`", value) return fmt.Errorf("<BigIntegerField.SetRaw> unknown value `%s`", value)
} }
@ -538,9 +542,10 @@ func (e *PositiveSmallIntegerField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := StrTo(d).Uint16() v, err := StrTo(d).Uint16()
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err
default: default:
return fmt.Errorf("<PositiveSmallIntegerField.SetRaw> unknown value `%s`", value) return fmt.Errorf("<PositiveSmallIntegerField.SetRaw> unknown value `%s`", value)
} }
@ -585,9 +590,10 @@ func (e *PositiveIntegerField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := StrTo(d).Uint32() v, err := StrTo(d).Uint32()
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err
default: default:
return fmt.Errorf("<PositiveIntegerField.SetRaw> unknown value `%s`", value) return fmt.Errorf("<PositiveIntegerField.SetRaw> unknown value `%s`", value)
} }
@ -632,9 +638,10 @@ func (e *PositiveBigIntegerField) SetRaw(value interface{}) error {
e.Set(d) e.Set(d)
case string: case string:
v, err := StrTo(d).Uint64() v, err := StrTo(d).Uint64()
if err != nil { if err == nil {
e.Set(v) e.Set(v)
} }
return err
default: default:
return fmt.Errorf("<PositiveBigIntegerField.SetRaw> unknown value `%s`", value) return fmt.Errorf("<PositiveBigIntegerField.SetRaw> unknown value `%s`", value)
} }

View File

@ -943,7 +943,7 @@ func (p *ControllerRegister) handleParamResponse(context *beecontext.Context, ex
context.RenderMethodResult(resultValue) context.RenderMethodResult(resultValue)
} }
} }
if !context.ResponseWriter.Started && context.Output.Status == 0 { if !context.ResponseWriter.Started && len(results) > 0 && context.Output.Status == 0 {
context.Output.SetStatus(200) context.Output.SetStatus(200)
} }
} }