mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 07:20:55 +00:00
Format code
This commit is contained in:
parent
9c51952db4
commit
30eb889a91
@ -296,7 +296,7 @@ func (c *ConfigContainer) getData(key string) (interface{}, error) {
|
|||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
{
|
{
|
||||||
tmpData = v.(map[string]interface{})
|
tmpData = v.(map[string]interface{})
|
||||||
if idx == len(keys) - 1 {
|
if idx == len(keys)-1 {
|
||||||
return tmpData, nil
|
return tmpData, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ package logs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"strings"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -374,14 +374,14 @@ func (w *fileLogWriter) deleteOldLog() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.Hourly {
|
if w.Hourly {
|
||||||
if !info.IsDir() && info.ModTime().Add(1 * time.Hour * time.Duration(w.MaxHours)).Before(time.Now()) {
|
if !info.IsDir() && info.ModTime().Add(1*time.Hour*time.Duration(w.MaxHours)).Before(time.Now()) {
|
||||||
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) &&
|
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) &&
|
||||||
strings.HasSuffix(filepath.Base(path), w.suffix) {
|
strings.HasSuffix(filepath.Base(path), w.suffix) {
|
||||||
os.Remove(path)
|
os.Remove(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if w.Daily {
|
} else if w.Daily {
|
||||||
if !info.IsDir() && info.ModTime().Add(24 * time.Hour * time.Duration(w.MaxDays)).Before(time.Now()) {
|
if !info.IsDir() && info.ModTime().Add(24*time.Hour*time.Duration(w.MaxDays)).Before(time.Now()) {
|
||||||
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) &&
|
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) &&
|
||||||
strings.HasSuffix(filepath.Base(path), w.suffix) {
|
strings.HasSuffix(filepath.Base(path), w.suffix) {
|
||||||
os.Remove(path)
|
os.Remove(path)
|
||||||
|
@ -198,8 +198,8 @@ func getDbCreateSQL(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
|
|||||||
column = strings.Replace(column, "%COL%", fi.column, -1)
|
column = strings.Replace(column, "%COL%", fi.column, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.description != "" && al.Driver!=DRSqlite {
|
if fi.description != "" && al.Driver != DRSqlite {
|
||||||
column += " " + fmt.Sprintf("COMMENT '%s'",fi.description)
|
column += " " + fmt.Sprintf("COMMENT '%s'", fi.description)
|
||||||
}
|
}
|
||||||
|
|
||||||
columns = append(columns, column)
|
columns = append(columns, column)
|
||||||
|
@ -61,7 +61,7 @@ func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error
|
|||||||
con += " - " + err.Error()
|
con += " - " + err.Error()
|
||||||
}
|
}
|
||||||
logMap["sql"] = fmt.Sprintf("%s-`%s`", query, strings.Join(cons, "`, `"))
|
logMap["sql"] = fmt.Sprintf("%s-`%s`", query, strings.Join(cons, "`, `"))
|
||||||
if LogFunc != nil{
|
if LogFunc != nil {
|
||||||
LogFunc(logMap)
|
LogFunc(logMap)
|
||||||
}
|
}
|
||||||
DebugLog.Println(con)
|
DebugLog.Println(con)
|
||||||
|
@ -296,7 +296,7 @@ func (c *ConfigContainer) getData(key string) (interface{}, error) {
|
|||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
{
|
{
|
||||||
tmpData = v.(map[string]interface{})
|
tmpData = v.(map[string]interface{})
|
||||||
if idx == len(keys) - 1 {
|
if idx == len(keys)-1 {
|
||||||
return tmpData, nil
|
return tmpData, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ package logs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"strings"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -374,14 +374,14 @@ func (w *fileLogWriter) deleteOldLog() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.Hourly {
|
if w.Hourly {
|
||||||
if !info.IsDir() && info.ModTime().Add(1 * time.Hour * time.Duration(w.MaxHours)).Before(time.Now()) {
|
if !info.IsDir() && info.ModTime().Add(1*time.Hour*time.Duration(w.MaxHours)).Before(time.Now()) {
|
||||||
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) &&
|
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) &&
|
||||||
strings.HasSuffix(filepath.Base(path), w.suffix) {
|
strings.HasSuffix(filepath.Base(path), w.suffix) {
|
||||||
os.Remove(path)
|
os.Remove(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if w.Daily {
|
} else if w.Daily {
|
||||||
if !info.IsDir() && info.ModTime().Add(24 * time.Hour * time.Duration(w.MaxDays)).Before(time.Now()) {
|
if !info.IsDir() && info.ModTime().Add(24*time.Hour*time.Duration(w.MaxDays)).Before(time.Now()) {
|
||||||
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) &&
|
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.fileNameOnly)) &&
|
||||||
strings.HasSuffix(filepath.Base(path), w.suffix) {
|
strings.HasSuffix(filepath.Base(path), w.suffix) {
|
||||||
os.Remove(path)
|
os.Remove(path)
|
||||||
|
@ -198,8 +198,8 @@ func getDbCreateSQL(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
|
|||||||
column = strings.Replace(column, "%COL%", fi.column, -1)
|
column = strings.Replace(column, "%COL%", fi.column, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.description != "" && al.Driver!=DRSqlite {
|
if fi.description != "" && al.Driver != DRSqlite {
|
||||||
column += " " + fmt.Sprintf("COMMENT '%s'",fi.description)
|
column += " " + fmt.Sprintf("COMMENT '%s'", fi.description)
|
||||||
}
|
}
|
||||||
|
|
||||||
columns = append(columns, column)
|
columns = append(columns, column)
|
||||||
|
@ -244,7 +244,7 @@ var _ dbQuerier = new(TxDB)
|
|||||||
var _ txEnder = new(TxDB)
|
var _ txEnder = new(TxDB)
|
||||||
|
|
||||||
func (t *TxDB) Prepare(query string) (*sql.Stmt, error) {
|
func (t *TxDB) Prepare(query string) (*sql.Stmt, error) {
|
||||||
return t.PrepareContext(context.Background(),query)
|
return t.PrepareContext(context.Background(), query)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TxDB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
|
func (t *TxDB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
|
||||||
@ -260,7 +260,7 @@ func (t *TxDB) ExecContext(ctx context.Context, query string, args ...interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TxDB) Query(query string, args ...interface{}) (*sql.Rows, error) {
|
func (t *TxDB) Query(query string, args ...interface{}) (*sql.Rows, error) {
|
||||||
return t.QueryContext(context.Background(),query,args...)
|
return t.QueryContext(context.Background(), query, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TxDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
|
func (t *TxDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
|
||||||
@ -268,7 +268,7 @@ func (t *TxDB) QueryContext(ctx context.Context, query string, args ...interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TxDB) QueryRow(query string, args ...interface{}) *sql.Row {
|
func (t *TxDB) QueryRow(query string, args ...interface{}) *sql.Row {
|
||||||
return t.QueryRowContext(context.Background(),query,args...)
|
return t.QueryRowContext(context.Background(), query, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TxDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
|
func (t *TxDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
|
||||||
|
@ -490,11 +490,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := RegisterDataBase("default", DBARGS.Driver, DBARGS.Source, common.KV{
|
err := RegisterDataBase("default", DBARGS.Driver, DBARGS.Source, common.KV{
|
||||||
Key:MaxIdleConnsKey,
|
Key: MaxIdleConnsKey,
|
||||||
Value:20,
|
Value: 20,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil{
|
if err != nil {
|
||||||
panic(fmt.Sprintf("can not register database: %v", err))
|
panic(fmt.Sprintf("can not register database: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error
|
|||||||
con += " - " + err.Error()
|
con += " - " + err.Error()
|
||||||
}
|
}
|
||||||
logMap["sql"] = fmt.Sprintf("%s-`%s`", query, strings.Join(cons, "`, `"))
|
logMap["sql"] = fmt.Sprintf("%s-`%s`", query, strings.Join(cons, "`, `"))
|
||||||
if LogFunc != nil{
|
if LogFunc != nil {
|
||||||
LogFunc(logMap)
|
LogFunc(logMap)
|
||||||
}
|
}
|
||||||
DebugLog.Println(con)
|
DebugLog.Println(con)
|
||||||
|
@ -110,7 +110,7 @@ type DQL interface {
|
|||||||
|
|
||||||
// Like Read(), but with "FOR UPDATE" clause, useful in transaction.
|
// Like Read(), but with "FOR UPDATE" clause, useful in transaction.
|
||||||
// Some databases are not support this feature.
|
// Some databases are not support this feature.
|
||||||
ReadForUpdate( md interface{}, cols ...string) error
|
ReadForUpdate(md interface{}, cols ...string) error
|
||||||
ReadForUpdateWithCtx(ctx context.Context, md interface{}, cols ...string) error
|
ReadForUpdateWithCtx(ctx context.Context, md interface{}, cols ...string) error
|
||||||
|
|
||||||
// Try to read a row from the database, or insert one if it doesn't exist
|
// Try to read a row from the database, or insert one if it doesn't exist
|
||||||
@ -129,14 +129,14 @@ type DQL interface {
|
|||||||
// args[2] int offset default offset 0
|
// args[2] int offset default offset 0
|
||||||
// args[3] string order for example : "-Id"
|
// args[3] string order for example : "-Id"
|
||||||
// make sure the relation is defined in model struct tags.
|
// make sure the relation is defined in model struct tags.
|
||||||
LoadRelated( md interface{}, name string, args ...interface{}) (int64, error)
|
LoadRelated(md interface{}, name string, args ...interface{}) (int64, error)
|
||||||
LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...interface{}) (int64, error)
|
LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...interface{}) (int64, error)
|
||||||
|
|
||||||
// create a models to models queryer
|
// create a models to models queryer
|
||||||
// for example:
|
// for example:
|
||||||
// post := Post{Id: 4}
|
// post := Post{Id: 4}
|
||||||
// m2m := Ormer.QueryM2M(&post, "Tags")
|
// m2m := Ormer.QueryM2M(&post, "Tags")
|
||||||
QueryM2M( md interface{}, name string) QueryM2Mer
|
QueryM2M(md interface{}, name string) QueryM2Mer
|
||||||
QueryM2MWithCtx(ctx context.Context, md interface{}, name string) QueryM2Mer
|
QueryM2MWithCtx(ctx context.Context, md interface{}, name string) QueryM2Mer
|
||||||
|
|
||||||
// return a QuerySeter for table operations.
|
// return a QuerySeter for table operations.
|
||||||
|
@ -31,13 +31,14 @@
|
|||||||
//
|
//
|
||||||
// more docs: http://beego.me/docs/module/session.md
|
// more docs: http://beego.me/docs/module/session.md
|
||||||
package redis_cluster
|
package redis_cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/astaxie/beego/session"
|
||||||
|
rediss "github.com/go-redis/redis"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"github.com/astaxie/beego/session"
|
|
||||||
rediss "github.com/go-redis/redis"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -101,7 +102,7 @@ func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c := rs.p
|
c := rs.p
|
||||||
c.Set(rs.sid, string(b), time.Duration(rs.maxlifetime) * time.Second)
|
c.Set(rs.sid, string(b), time.Duration(rs.maxlifetime)*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provider redis_cluster session provider
|
// Provider redis_cluster session provider
|
||||||
@ -191,10 +192,10 @@ func (rp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error)
|
|||||||
// oldsid doesn't exists, set the new sid directly
|
// oldsid doesn't exists, set the new sid directly
|
||||||
// ignore error here, since if it return error
|
// ignore error here, since if it return error
|
||||||
// the existed value will be 0
|
// the existed value will be 0
|
||||||
c.Set(sid, "", time.Duration(rp.maxlifetime) * time.Second)
|
c.Set(sid, "", time.Duration(rp.maxlifetime)*time.Second)
|
||||||
} else {
|
} else {
|
||||||
c.Rename(oldsid, sid)
|
c.Rename(oldsid, sid)
|
||||||
c.Expire(sid, time.Duration(rp.maxlifetime) * time.Second)
|
c.Expire(sid, time.Duration(rp.maxlifetime)*time.Second)
|
||||||
}
|
}
|
||||||
return rp.SessionRead(sid)
|
return rp.SessionRead(sid)
|
||||||
}
|
}
|
||||||
|
@ -369,8 +369,7 @@ func TestFileSessionStore_SessionRelease(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.Set(i, i)
|
||||||
s.Set(i,i)
|
|
||||||
s.SessionRelease(nil)
|
s.SessionRelease(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ func TestSpec(t *testing.T) {
|
|||||||
func TestTask_Run(t *testing.T) {
|
func TestTask_Run(t *testing.T) {
|
||||||
cnt := -1
|
cnt := -1
|
||||||
task := func() error {
|
task := func() error {
|
||||||
cnt ++
|
cnt++
|
||||||
fmt.Printf("Hello, world! %d \n", cnt)
|
fmt.Printf("Hello, world! %d \n", cnt)
|
||||||
return errors.New(fmt.Sprintf("Hello, world! %d", cnt))
|
return errors.New(fmt.Sprintf("Hello, world! %d", cnt))
|
||||||
}
|
}
|
||||||
tk := NewTask("taska", "0/30 * * * * *", task)
|
tk := NewTask("taska", "0/30 * * * * *", task)
|
||||||
for i := 0; i < 200 ; i ++ {
|
for i := 0; i < 200; i++ {
|
||||||
e := tk.Run()
|
e := tk.Run()
|
||||||
assert.NotNil(t, e)
|
assert.NotNil(t, e)
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ func parseFunc(vfunc, key string, label string) (v ValidFunc, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tParams, err := trim(name, key+"."+ name + "." + label, params)
|
tParams, err := trim(name, key+"."+name+"."+label, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,14 @@
|
|||||||
//
|
//
|
||||||
// more docs: http://beego.me/docs/module/session.md
|
// more docs: http://beego.me/docs/module/session.md
|
||||||
package redis_cluster
|
package redis_cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/astaxie/beego/session"
|
||||||
|
rediss "github.com/go-redis/redis"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"github.com/astaxie/beego/session"
|
|
||||||
rediss "github.com/go-redis/redis"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -101,7 +102,7 @@ func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c := rs.p
|
c := rs.p
|
||||||
c.Set(rs.sid, string(b), time.Duration(rs.maxlifetime) * time.Second)
|
c.Set(rs.sid, string(b), time.Duration(rs.maxlifetime)*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provider redis_cluster session provider
|
// Provider redis_cluster session provider
|
||||||
@ -191,10 +192,10 @@ func (rp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error)
|
|||||||
// oldsid doesn't exists, set the new sid directly
|
// oldsid doesn't exists, set the new sid directly
|
||||||
// ignore error here, since if it return error
|
// ignore error here, since if it return error
|
||||||
// the existed value will be 0
|
// the existed value will be 0
|
||||||
c.Set(sid, "", time.Duration(rp.maxlifetime) * time.Second)
|
c.Set(sid, "", time.Duration(rp.maxlifetime)*time.Second)
|
||||||
} else {
|
} else {
|
||||||
c.Rename(oldsid, sid)
|
c.Rename(oldsid, sid)
|
||||||
c.Expire(sid, time.Duration(rp.maxlifetime) * time.Second)
|
c.Expire(sid, time.Duration(rp.maxlifetime)*time.Second)
|
||||||
}
|
}
|
||||||
return rp.SessionRead(sid)
|
return rp.SessionRead(sid)
|
||||||
}
|
}
|
||||||
|
@ -369,8 +369,7 @@ func TestFileSessionStore_SessionRelease(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.Set(i, i)
|
||||||
s.Set(i,i)
|
|
||||||
s.SessionRelease(nil)
|
s.SessionRelease(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ func TestSpec(t *testing.T) {
|
|||||||
func TestTask_Run(t *testing.T) {
|
func TestTask_Run(t *testing.T) {
|
||||||
cnt := -1
|
cnt := -1
|
||||||
task := func() error {
|
task := func() error {
|
||||||
cnt ++
|
cnt++
|
||||||
fmt.Printf("Hello, world! %d \n", cnt)
|
fmt.Printf("Hello, world! %d \n", cnt)
|
||||||
return errors.New(fmt.Sprintf("Hello, world! %d", cnt))
|
return errors.New(fmt.Sprintf("Hello, world! %d", cnt))
|
||||||
}
|
}
|
||||||
tk := NewTask("taska", "0/30 * * * * *", task)
|
tk := NewTask("taska", "0/30 * * * * *", task)
|
||||||
for i := 0; i < 200 ; i ++ {
|
for i := 0; i < 200; i++ {
|
||||||
e := tk.Run()
|
e := tk.Run()
|
||||||
assert.NotNil(t, e)
|
assert.NotNil(t, e)
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ func parseFunc(vfunc, key string, label string) (v ValidFunc, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tParams, err := trim(name, key+"."+ name + "." + label, params)
|
tParams, err := trim(name, key+"."+name+"."+label, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user