mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 21:11:29 +00:00
bee fix
This commit is contained in:
parent
94bde3a777
commit
2db8c753fd
14
cache/cache_test.go
vendored
14
cache/cache_test.go
vendored
@ -26,7 +26,7 @@ func TestCache(t *testing.T) {
|
|||||||
t.Error("init err")
|
t.Error("init err")
|
||||||
}
|
}
|
||||||
timeoutDuration := 10 * time.Second
|
timeoutDuration := 10 * time.Second
|
||||||
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", 1, timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
@ -43,7 +43,7 @@ func TestCache(t *testing.T) {
|
|||||||
t.Error("check err")
|
t.Error("check err")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", 1, timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ func TestCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//test GetMulti
|
//test GetMulti
|
||||||
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "author", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
@ -78,7 +78,7 @@ func TestCache(t *testing.T) {
|
|||||||
t.Error("get err")
|
t.Error("get err")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie1", "author1", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie1") {
|
if !bm.IsExist("astaxie1") {
|
||||||
@ -103,7 +103,7 @@ func TestFileCache(t *testing.T) {
|
|||||||
t.Error("init err")
|
t.Error("init err")
|
||||||
}
|
}
|
||||||
timeoutDuration := 10 * time.Second
|
timeoutDuration := 10 * time.Second
|
||||||
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", 1, timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
@ -135,7 +135,7 @@ func TestFileCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//test string
|
//test string
|
||||||
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "author", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
@ -146,7 +146,7 @@ func TestFileCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//test GetMulti
|
//test GetMulti
|
||||||
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie1", "author1", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie1") {
|
if !bm.IsExist("astaxie1") {
|
||||||
|
8
cache/memcache/memcache_test.go
vendored
8
cache/memcache/memcache_test.go
vendored
@ -30,7 +30,7 @@ func TestMemcacheCache(t *testing.T) {
|
|||||||
t.Error("init err")
|
t.Error("init err")
|
||||||
}
|
}
|
||||||
timeoutDuration := 10 * time.Second
|
timeoutDuration := 10 * time.Second
|
||||||
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "1", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
@ -42,7 +42,7 @@ func TestMemcacheCache(t *testing.T) {
|
|||||||
if bm.IsExist("astaxie") {
|
if bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error("check err")
|
||||||
}
|
}
|
||||||
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "1", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ func TestMemcacheCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//test string
|
//test string
|
||||||
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "author", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
@ -83,7 +83,7 @@ func TestMemcacheCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//test GetMulti
|
//test GetMulti
|
||||||
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie1", "author1", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie1") {
|
if !bm.IsExist("astaxie1") {
|
||||||
|
8
cache/redis/redis_test.go
vendored
8
cache/redis/redis_test.go
vendored
@ -29,7 +29,7 @@ func TestRedisCache(t *testing.T) {
|
|||||||
t.Error("init err")
|
t.Error("init err")
|
||||||
}
|
}
|
||||||
timeoutDuration := 10 * time.Second
|
timeoutDuration := 10 * time.Second
|
||||||
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", 1, timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
@ -41,7 +41,7 @@ func TestRedisCache(t *testing.T) {
|
|||||||
if bm.IsExist("astaxie") {
|
if bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error("check err")
|
||||||
}
|
}
|
||||||
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", 1, timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ func TestRedisCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//test string
|
//test string
|
||||||
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "author", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
@ -82,7 +82,7 @@ func TestRedisCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//test GetMulti
|
//test GetMulti
|
||||||
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie1", "author1", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie1") {
|
if !bm.IsExist("astaxie1") {
|
||||||
|
8
cache/ssdb/ssdb_test.go
vendored
8
cache/ssdb/ssdb_test.go
vendored
@ -19,7 +19,7 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
timeoutDuration := 10 * time.Second
|
timeoutDuration := 10 * time.Second
|
||||||
//timeoutDuration := -10*time.Second if timeoutDuration is negtive,it means permanent
|
//timeoutDuration := -10*time.Second if timeoutDuration is negtive,it means permanent
|
||||||
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration); err != nil {
|
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if !ssdb.IsExist("ssdb") {
|
if !ssdb.IsExist("ssdb") {
|
||||||
@ -27,7 +27,7 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get test done
|
// Get test done
|
||||||
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration); err != nil {
|
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//inc/dec test done
|
//inc/dec test done
|
||||||
if err = ssdb.Put("ssdb", "2", timeoutDuration); err != nil {
|
if err = ssdb.Put("ssdb", "2", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if err = ssdb.Incr("ssdb"); err != nil {
|
if err = ssdb.Incr("ssdb"); err != nil {
|
||||||
@ -52,7 +52,7 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test del
|
// test del
|
||||||
if err = ssdb.Put("ssdb", "3", timeoutDuration); err != nil {
|
if err = ssdb.Put("ssdb", "3", timeoutDuration*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error("set Error", err)
|
||||||
}
|
}
|
||||||
if v, err := strconv.Atoi(ssdb.Get("ssdb").(string)); err != nil || v != 3 {
|
if v, err := strconv.Atoi(ssdb.Get("ssdb").(string)); err != nil || v != 3 {
|
||||||
|
@ -100,7 +100,7 @@ func TestSubDomain(t *testing.T) {
|
|||||||
|
|
||||||
/* TODO Fix this
|
/* TODO Fix this
|
||||||
r, _ = http.NewRequest("GET", "http://127.0.0.1/", nil)
|
r, _ = http.NewRequest("GET", "http://127.0.0.1/", nil)
|
||||||
beegoInput.Request = r
|
beegoInput.Context.Request = r
|
||||||
if beegoInput.SubDomains() != "" {
|
if beegoInput.SubDomains() != "" {
|
||||||
t.Fatal("Subdomain parse error, got " + beegoInput.SubDomains())
|
t.Fatal("Subdomain parse error, got " + beegoInput.SubDomains())
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ func (m *Migration) Reset() {
|
|||||||
func (m *Migration) Exec(name, status string) error {
|
func (m *Migration) Exec(name, status string) error {
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
for _, s := range m.sqls {
|
for _, s := range m.sqls {
|
||||||
beego.Info("exec sql:", s)
|
logs.Info("exec sql:", s)
|
||||||
r := o.Raw(s)
|
r := o.Raw(s)
|
||||||
_, err := r.Exec()
|
_, err := r.Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -144,20 +144,20 @@ func Upgrade(lasttime int64) error {
|
|||||||
i := 0
|
i := 0
|
||||||
for _, v := range sm {
|
for _, v := range sm {
|
||||||
if v.created > lasttime {
|
if v.created > lasttime {
|
||||||
beego.Info("start upgrade", v.name)
|
logs.Info("start upgrade", v.name)
|
||||||
v.m.Reset()
|
v.m.Reset()
|
||||||
v.m.Up()
|
v.m.Up()
|
||||||
err := v.m.Exec(v.name, "up")
|
err := v.m.Exec(v.name, "up")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Error("execute error:", err)
|
logs.Error("execute error:", err)
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
beego.Info("end upgrade:", v.name)
|
logs.Info("end upgrade:", v.name)
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
beego.Info("total success upgrade:", i, " migration")
|
logs.Info("total success upgrade:", i, " migration")
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -165,20 +165,20 @@ func Upgrade(lasttime int64) error {
|
|||||||
// Rollback rollback the migration by the name
|
// Rollback rollback the migration by the name
|
||||||
func Rollback(name string) error {
|
func Rollback(name string) error {
|
||||||
if v, ok := migrationMap[name]; ok {
|
if v, ok := migrationMap[name]; ok {
|
||||||
beego.Info("start rollback")
|
logs.Info("start rollback")
|
||||||
v.Reset()
|
v.Reset()
|
||||||
v.Down()
|
v.Down()
|
||||||
err := v.Exec(name, "down")
|
err := v.Exec(name, "down")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Error("execute error:", err)
|
logs.Error("execute error:", err)
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
beego.Info("end rollback")
|
logs.Info("end rollback")
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
beego.Error("not exist the migrationMap name:" + name)
|
logs.Error("not exist the migrationMap name:" + name)
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
return errors.New("not exist the migrationMap name:" + name)
|
return errors.New("not exist the migrationMap name:" + name)
|
||||||
}
|
}
|
||||||
@ -191,23 +191,23 @@ func Reset() error {
|
|||||||
for j := len(sm) - 1; j >= 0; j-- {
|
for j := len(sm) - 1; j >= 0; j-- {
|
||||||
v := sm[j]
|
v := sm[j]
|
||||||
if isRollBack(v.name) {
|
if isRollBack(v.name) {
|
||||||
beego.Info("skip the", v.name)
|
logs.Info("skip the", v.name)
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
beego.Info("start reset:", v.name)
|
logs.Info("start reset:", v.name)
|
||||||
v.m.Reset()
|
v.m.Reset()
|
||||||
v.m.Down()
|
v.m.Down()
|
||||||
err := v.m.Exec(v.name, "down")
|
err := v.m.Exec(v.name, "down")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Error("execute error:", err)
|
logs.Error("execute error:", err)
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
beego.Info("end reset:", v.name)
|
logs.Info("end reset:", v.name)
|
||||||
}
|
}
|
||||||
beego.Info("total success reset:", i, " migration")
|
logs.Info("total success reset:", i, " migration")
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ func Reset() error {
|
|||||||
func Refresh() error {
|
func Refresh() error {
|
||||||
err := Reset()
|
err := Reset()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Error("execute error:", err)
|
logs.Error("execute error:", err)
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ func isRollBack(name string) bool {
|
|||||||
var maps []orm.Params
|
var maps []orm.Params
|
||||||
num, err := o.Raw("select * from migrations where `name` = ? order by id_migration desc", name).Values(&maps)
|
num, err := o.Raw("select * from migrations where `name` = ? order by id_migration desc", name).Values(&maps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Info("get name has error", err)
|
logs.Info("get name has error", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if num <= 0 {
|
if num <= 0 {
|
||||||
|
@ -69,6 +69,7 @@ import (
|
|||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/cache"
|
"github.com/astaxie/beego/cache"
|
||||||
"github.com/astaxie/beego/context"
|
"github.com/astaxie/beego/context"
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/astaxie/beego/utils"
|
"github.com/astaxie/beego/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -139,7 +140,7 @@ func (c *Captcha) Handler(ctx *context.Context) {
|
|||||||
if err := c.store.Put(key, chars, c.Expiration); err != nil {
|
if err := c.store.Put(key, chars, c.Expiration); err != nil {
|
||||||
ctx.Output.SetStatus(500)
|
ctx.Output.SetStatus(500)
|
||||||
ctx.WriteString("captcha reload error")
|
ctx.WriteString("captcha reload error")
|
||||||
beego.Error("Reload Create Captcha Error:", err)
|
logs.Error("Reload Create Captcha Error:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -154,7 +155,7 @@ func (c *Captcha) Handler(ctx *context.Context) {
|
|||||||
|
|
||||||
img := NewImage(chars, c.StdWidth, c.StdHeight)
|
img := NewImage(chars, c.StdWidth, c.StdHeight)
|
||||||
if _, err := img.WriteTo(ctx.ResponseWriter); err != nil {
|
if _, err := img.WriteTo(ctx.ResponseWriter); err != nil {
|
||||||
beego.Error("Write Captcha Image Error:", err)
|
logs.Error("Write Captcha Image Error:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +163,7 @@ func (c *Captcha) Handler(ctx *context.Context) {
|
|||||||
func (c *Captcha) CreateCaptchaHTML() template.HTML {
|
func (c *Captcha) CreateCaptchaHTML() template.HTML {
|
||||||
value, err := c.CreateCaptcha()
|
value, err := c.CreateCaptcha()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Error("Create Captcha Error:", err)
|
logs.Error("Create Captcha Error:", err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"github.com/astaxie/beego/context"
|
"github.com/astaxie/beego/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetPaginator Instantiates a Paginator and assigns it to context.Input.Data["paginator"].
|
// SetPaginator Instantiates a Paginator and assigns it to context.Input.Data("paginator").
|
||||||
func SetPaginator(context *context.Context, per int, nums int64) (paginator *Paginator) {
|
func SetPaginator(context *context.Context, per int, nums int64) (paginator *Paginator) {
|
||||||
paginator = NewPaginator(context.Request, per, nums)
|
paginator = NewPaginator(context.Request, per, nums)
|
||||||
context.Input.SetData("paginator", &paginator)
|
context.Input.SetData("paginator", &paginator)
|
||||||
|
Loading…
Reference in New Issue
Block a user