mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:10:54 +00:00
Merge remote-tracking branch 'upstream/develop' into develop
This commit is contained in:
commit
08ea9b3339
@ -21,6 +21,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -184,10 +185,17 @@ func (ini *IniConfig) parseData(dir string, data []byte) (*IniConfigContainer, e
|
|||||||
|
|
||||||
// ParseData parse ini the data
|
// ParseData parse ini the data
|
||||||
// When include other.conf,other.conf is either absolute directory
|
// When include other.conf,other.conf is either absolute directory
|
||||||
// or under beego in default temporary directory(/tmp/beego).
|
// or under beego in default temporary directory(/tmp/beego[-username]).
|
||||||
func (ini *IniConfig) ParseData(data []byte) (Configer, error) {
|
func (ini *IniConfig) ParseData(data []byte) (Configer, error) {
|
||||||
dir := filepath.Join(os.TempDir(), "beego")
|
dir := "beego"
|
||||||
os.MkdirAll(dir, os.ModePerm)
|
currentUser, err := user.Current()
|
||||||
|
if err == nil {
|
||||||
|
dir = "beego-" + currentUser.Username
|
||||||
|
}
|
||||||
|
dir = filepath.Join(os.TempDir(), dir)
|
||||||
|
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return ini.parseData(dir, data)
|
return ini.parseData(dir, data)
|
||||||
}
|
}
|
||||||
|
@ -73,8 +73,8 @@ func TestBind(t *testing.T) {
|
|||||||
{"/?human.ID=888&human.Nick=astaxie&human.Ms=true&human[Pwd]=pass", []testItem{{"human", Human{}, Human{ID: 888, Nick: "astaxie", Ms: true, Pwd: "pass"}}}},
|
{"/?human.ID=888&human.Nick=astaxie&human.Ms=true&human[Pwd]=pass", []testItem{{"human", Human{}, Human{ID: 888, Nick: "astaxie", Ms: true, Pwd: "pass"}}}},
|
||||||
{"/?human[0].ID=888&human[0].Nick=astaxie&human[0].Ms=true&human[0][Pwd]=pass01&human[1].ID=999&human[1].Nick=ysqi&human[1].Ms=On&human[1].Pwd=pass02",
|
{"/?human[0].ID=888&human[0].Nick=astaxie&human[0].Ms=true&human[0][Pwd]=pass01&human[1].ID=999&human[1].Nick=ysqi&human[1].Ms=On&human[1].Pwd=pass02",
|
||||||
[]testItem{{"human", []Human{}, []Human{
|
[]testItem{{"human", []Human{}, []Human{
|
||||||
Human{ID: 888, Nick: "astaxie", Ms: true, Pwd: "pass01"},
|
{ID: 888, Nick: "astaxie", Ms: true, Pwd: "pass01"},
|
||||||
Human{ID: 999, Nick: "ysqi", Ms: true, Pwd: "pass02"},
|
{ID: 999, Nick: "ysqi", Ms: true, Pwd: "pass02"},
|
||||||
}}}},
|
}}}},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -172,10 +172,10 @@ func TestAdditionalViewPaths(t *testing.T) {
|
|||||||
t.Fatal("TestAdditionalViewPaths expected error")
|
t.Fatal("TestAdditionalViewPaths expected error")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ctrl.RenderString();
|
ctrl.RenderString()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ctrl.TplName = "file2.tpl"
|
ctrl.TplName = "file2.tpl"
|
||||||
ctrl.ViewPath = dir2
|
ctrl.ViewPath = dir2
|
||||||
ctrl.RenderString();
|
ctrl.RenderString()
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func signature(project *LogProject, method, uri string,
|
|||||||
var keys sort.StringSlice
|
var keys sort.StringSlice
|
||||||
|
|
||||||
vals := u.Query()
|
vals := u.Query()
|
||||||
for k, _ := range vals {
|
for k := range vals {
|
||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,4 +109,3 @@ func signature(project *LogProject, method, uri string,
|
|||||||
digest = base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
digest = base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ func TestFileRotate_05(t *testing.T) {
|
|||||||
testFileDailyRotate(t, fn1, fn2)
|
testFileDailyRotate(t, fn1, fn2)
|
||||||
os.Remove(fn)
|
os.Remove(fn)
|
||||||
}
|
}
|
||||||
func TestFileRotate_06(t *testing.T) {//test file mode
|
func TestFileRotate_06(t *testing.T) { //test file mode
|
||||||
log := NewLogger(10000)
|
log := NewLogger(10000)
|
||||||
log.SetLogger("file", `{"filename":"test3.log","maxlines":4}`)
|
log.SetLogger("file", `{"filename":"test3.log","maxlines":4}`)
|
||||||
log.Debug("debug")
|
log.Debug("debug")
|
||||||
@ -174,7 +174,7 @@ func TestFileRotate_06(t *testing.T) {//test file mode
|
|||||||
log.Critical("critical")
|
log.Critical("critical")
|
||||||
log.Emergency("emergency")
|
log.Emergency("emergency")
|
||||||
rotateName := "test3" + fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), 1) + ".log"
|
rotateName := "test3" + fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), 1) + ".log"
|
||||||
s,_:=os.Lstat(rotateName)
|
s, _ := os.Lstat(rotateName)
|
||||||
if s.Mode() != 0440 {
|
if s.Mode() != 0440 {
|
||||||
os.Remove(rotateName)
|
os.Remove(rotateName)
|
||||||
os.Remove("test3.log")
|
os.Remove("test3.log")
|
||||||
|
@ -592,7 +592,7 @@ func (d *dbBase) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, a
|
|||||||
row := q.QueryRow(query, values...)
|
row := q.QueryRow(query, values...)
|
||||||
var id int64
|
var id int64
|
||||||
err = row.Scan(&id)
|
err = row.Scan(&id)
|
||||||
if err.Error() == `pq: syntax error at or near "ON"` {
|
if err != nil && err.Error() == `pq: syntax error at or near "ON"` {
|
||||||
err = fmt.Errorf("postgres version must 9.5 or higher")
|
err = fmt.Errorf("postgres version must 9.5 or higher")
|
||||||
}
|
}
|
||||||
return id, err
|
return id, err
|
||||||
|
@ -230,9 +230,12 @@ func BuildTemplate(dir string, files ...string) error {
|
|||||||
|
|
||||||
func getTplDeep(root, file, parent string, t *template.Template) (*template.Template, [][]string, error) {
|
func getTplDeep(root, file, parent string, t *template.Template) (*template.Template, [][]string, error) {
|
||||||
var fileAbsPath string
|
var fileAbsPath string
|
||||||
|
var rParent string
|
||||||
if filepath.HasPrefix(file, "../") {
|
if filepath.HasPrefix(file, "../") {
|
||||||
|
rParent = filepath.Join(filepath.Dir(parent), file)
|
||||||
fileAbsPath = filepath.Join(root, filepath.Dir(parent), file)
|
fileAbsPath = filepath.Join(root, filepath.Dir(parent), file)
|
||||||
} else {
|
} else {
|
||||||
|
rParent = file
|
||||||
fileAbsPath = filepath.Join(root, file)
|
fileAbsPath = filepath.Join(root, file)
|
||||||
}
|
}
|
||||||
if e := utils.FileExists(fileAbsPath); !e {
|
if e := utils.FileExists(fileAbsPath); !e {
|
||||||
@ -257,7 +260,7 @@ func getTplDeep(root, file, parent string, t *template.Template) (*template.Temp
|
|||||||
if !HasTemplateExt(m[1]) {
|
if !HasTemplateExt(m[1]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_, _, err = getTplDeep(root, m[1], file, t)
|
_, _, err = getTplDeep(root, m[1], rParent, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, [][]string{}, err
|
return nil, [][]string{}, err
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ func (m *URLMap) GetMap() map[string]interface{} {
|
|||||||
func (m *URLMap) GetMapData() []map[string]interface{} {
|
func (m *URLMap) GetMapData() []map[string]interface{} {
|
||||||
m.lock.Lock()
|
m.lock.Lock()
|
||||||
defer m.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
|
|
||||||
var resultLists []map[string]interface{}
|
var resultLists []map[string]interface{}
|
||||||
|
|
||||||
for k, v := range m.urlmap {
|
for k, v := range m.urlmap {
|
||||||
|
@ -427,6 +427,7 @@ func run() {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
case <-changed:
|
case <-changed:
|
||||||
|
now = time.Now().Local()
|
||||||
continue
|
continue
|
||||||
case <-stop:
|
case <-stop:
|
||||||
return
|
return
|
||||||
|
25
tree.go
25
tree.go
@ -288,10 +288,10 @@ func (t *Tree) Match(pattern string, ctx *context.Context) (runObject interface{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
w := make([]string, 0, 20)
|
w := make([]string, 0, 20)
|
||||||
return t.match(pattern, w, ctx)
|
return t.match(pattern[1:], pattern, w, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tree) match(pattern string, wildcardValues []string, ctx *context.Context) (runObject interface{}) {
|
func (t *Tree) match(treePattern string, pattern string, wildcardValues []string, ctx *context.Context) (runObject interface{}) {
|
||||||
if len(pattern) > 0 {
|
if len(pattern) > 0 {
|
||||||
i := 0
|
i := 0
|
||||||
for ; i < len(pattern) && pattern[i] == '/'; i++ {
|
for ; i < len(pattern) && pattern[i] == '/'; i++ {
|
||||||
@ -301,13 +301,13 @@ func (t *Tree) match(pattern string, wildcardValues []string, ctx *context.Conte
|
|||||||
// Handle leaf nodes:
|
// Handle leaf nodes:
|
||||||
if len(pattern) == 0 {
|
if len(pattern) == 0 {
|
||||||
for _, l := range t.leaves {
|
for _, l := range t.leaves {
|
||||||
if ok := l.match(wildcardValues, ctx); ok {
|
if ok := l.match(treePattern, wildcardValues, ctx); ok {
|
||||||
return l.runObject
|
return l.runObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if t.wildcard != nil {
|
if t.wildcard != nil {
|
||||||
for _, l := range t.wildcard.leaves {
|
for _, l := range t.wildcard.leaves {
|
||||||
if ok := l.match(wildcardValues, ctx); ok {
|
if ok := l.match(treePattern, wildcardValues, ctx); ok {
|
||||||
return l.runObject
|
return l.runObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -327,7 +327,12 @@ func (t *Tree) match(pattern string, wildcardValues []string, ctx *context.Conte
|
|||||||
}
|
}
|
||||||
for _, subTree := range t.fixrouters {
|
for _, subTree := range t.fixrouters {
|
||||||
if subTree.prefix == seg {
|
if subTree.prefix == seg {
|
||||||
runObject = subTree.match(pattern, wildcardValues, ctx)
|
if len(pattern) != 0 && pattern[0] == '/' {
|
||||||
|
treePattern = pattern[1:]
|
||||||
|
} else {
|
||||||
|
treePattern = pattern
|
||||||
|
}
|
||||||
|
runObject = subTree.match(treePattern, pattern, wildcardValues, ctx)
|
||||||
if runObject != nil {
|
if runObject != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -339,7 +344,7 @@ func (t *Tree) match(pattern string, wildcardValues []string, ctx *context.Conte
|
|||||||
if strings.HasSuffix(seg, str) {
|
if strings.HasSuffix(seg, str) {
|
||||||
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(pattern, wildcardValues, ctx)
|
runObject = subTree.match(treePattern, pattern, wildcardValues, ctx)
|
||||||
if runObject != nil {
|
if runObject != nil {
|
||||||
ctx.Input.SetParam(":ext", str[1:])
|
ctx.Input.SetParam(":ext", str[1:])
|
||||||
}
|
}
|
||||||
@ -349,7 +354,7 @@ func (t *Tree) match(pattern string, wildcardValues []string, ctx *context.Conte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if runObject == nil && t.wildcard != nil {
|
if runObject == nil && t.wildcard != nil {
|
||||||
runObject = t.wildcard.match(pattern, append(wildcardValues, seg), ctx)
|
runObject = t.wildcard.match(treePattern, pattern, append(wildcardValues, seg), ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if runObject == nil && len(t.leaves) > 0 {
|
if runObject == nil && len(t.leaves) > 0 {
|
||||||
@ -368,7 +373,7 @@ func (t *Tree) match(pattern string, wildcardValues []string, ctx *context.Conte
|
|||||||
wildcardValues = append(wildcardValues, pattern[start:i])
|
wildcardValues = append(wildcardValues, pattern[start:i])
|
||||||
}
|
}
|
||||||
for _, l := range t.leaves {
|
for _, l := range t.leaves {
|
||||||
if ok := l.match(wildcardValues, ctx); ok {
|
if ok := l.match(treePattern, wildcardValues, ctx); ok {
|
||||||
return l.runObject
|
return l.runObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -386,7 +391,7 @@ type leafInfo struct {
|
|||||||
runObject interface{}
|
runObject interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (leaf *leafInfo) match(wildcardValues []string, ctx *context.Context) (ok bool) {
|
func (leaf *leafInfo) match(treePattern string, wildcardValues []string, ctx *context.Context) (ok bool) {
|
||||||
//fmt.Println("Leaf:", wildcardValues, leaf.wildcards, leaf.regexps)
|
//fmt.Println("Leaf:", wildcardValues, leaf.wildcards, leaf.regexps)
|
||||||
if leaf.regexps == nil {
|
if leaf.regexps == nil {
|
||||||
if len(wildcardValues) == 0 && len(leaf.wildcards) == 0 { // static path
|
if len(wildcardValues) == 0 && len(leaf.wildcards) == 0 { // static path
|
||||||
@ -394,7 +399,7 @@ func (leaf *leafInfo) match(wildcardValues []string, ctx *context.Context) (ok b
|
|||||||
}
|
}
|
||||||
// match *
|
// match *
|
||||||
if len(leaf.wildcards) == 1 && leaf.wildcards[0] == ":splat" {
|
if len(leaf.wildcards) == 1 && leaf.wildcards[0] == ":splat" {
|
||||||
ctx.Input.SetParam(":splat", path.Join(wildcardValues...))
|
ctx.Input.SetParam(":splat", treePattern)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// match *.* or :id
|
// match *.* or :id
|
||||||
|
@ -42,7 +42,7 @@ func init() {
|
|||||||
routers = append(routers, testinfo{"/", "/", nil})
|
routers = append(routers, testinfo{"/", "/", nil})
|
||||||
routers = append(routers, testinfo{"/customer/login", "/customer/login", nil})
|
routers = append(routers, testinfo{"/customer/login", "/customer/login", nil})
|
||||||
routers = append(routers, testinfo{"/customer/login", "/customer/login.json", map[string]string{":ext": "json"}})
|
routers = append(routers, testinfo{"/customer/login", "/customer/login.json", map[string]string{":ext": "json"}})
|
||||||
routers = append(routers, testinfo{"/*", "/customer/123", map[string]string{":splat": "customer/123"}})
|
routers = append(routers, testinfo{"/*", "/http://customer/123/", map[string]string{":splat": "http://customer/123/"}})
|
||||||
routers = append(routers, testinfo{"/*", "/customer/2009/12/11", map[string]string{":splat": "customer/2009/12/11"}})
|
routers = append(routers, testinfo{"/*", "/customer/2009/12/11", map[string]string{":splat": "customer/2009/12/11"}})
|
||||||
routers = append(routers, testinfo{"/aa/*/bb", "/aa/2009/bb", map[string]string{":splat": "2009"}})
|
routers = append(routers, testinfo{"/aa/*/bb", "/aa/2009/bb", map[string]string{":splat": "2009"}})
|
||||||
routers = append(routers, testinfo{"/cc/*/dd", "/cc/2009/11/dd", map[string]string{":splat": "2009/11"}})
|
routers = append(routers, testinfo{"/cc/*/dd", "/cc/2009/11/dd", map[string]string{":splat": "2009/11"}})
|
||||||
|
Loading…
Reference in New Issue
Block a user