mirror of
https://github.com/astaxie/beego.git
synced 2024-11-24 22:10:54 +00:00
fix ineffectual
This commit is contained in:
parent
3e29078f68
commit
aa8f7bc146
@ -325,7 +325,10 @@ func (c *IniConfigContainer) SaveConfigFile(filename string) (err error) {
|
||||
|
||||
// Get section or key comments. Fixed #1607
|
||||
getCommentStr := func(section, key string) string {
|
||||
comment, ok := "", false
|
||||
var (
|
||||
comment string
|
||||
ok bool
|
||||
)
|
||||
if len(key) == 0 {
|
||||
comment, ok = c.sectionComment[section]
|
||||
} else {
|
||||
|
@ -361,7 +361,7 @@ func isParameterChar(b byte) bool {
|
||||
}
|
||||
|
||||
func (cw *ansiColorWriter) Write(p []byte) (int, error) {
|
||||
r, nw, first, last := 0, 0, 0, 0
|
||||
var r, nw, first, last int
|
||||
if cw.mode != DiscardNonColorEscSeq {
|
||||
cw.state = outsideCsiCode
|
||||
cw.resetBuffer()
|
||||
|
10
logs/file.go
10
logs/file.go
@ -259,7 +259,7 @@ func (w *fileLogWriter) doRotate(logTime time.Time) error {
|
||||
}
|
||||
// return error if the last file checked still existed
|
||||
if err == nil {
|
||||
return fmt.Errorf("Rotate: Cannot find free log number to rename %s\n", w.Filename)
|
||||
return fmt.Errorf("Rotate: Cannot find free log number to rename %s", w.Filename)
|
||||
}
|
||||
|
||||
// close fileWriter before rename
|
||||
@ -268,6 +268,9 @@ func (w *fileLogWriter) doRotate(logTime time.Time) error {
|
||||
// Rename the file to its new found name
|
||||
// even if occurs error,we MUST guarantee to restart new logger
|
||||
err = os.Rename(w.Filename, fName)
|
||||
if err != nil {
|
||||
goto RESTART_LOGGER
|
||||
}
|
||||
err = os.Chmod(fName, os.FileMode(0440))
|
||||
// re-start logger
|
||||
RESTART_LOGGER:
|
||||
@ -276,13 +279,12 @@ RESTART_LOGGER:
|
||||
go w.deleteOldLog()
|
||||
|
||||
if startLoggerErr != nil {
|
||||
return fmt.Errorf("Rotate StartLogger: %s\n", startLoggerErr)
|
||||
return fmt.Errorf("Rotate StartLogger: %s", startLoggerErr)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("Rotate: %s\n", err)
|
||||
return fmt.Errorf("Rotate: %s", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (w *fileLogWriter) deleteOldLog() {
|
||||
|
@ -1110,7 +1110,7 @@ func (d *dbBase) Count(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition
|
||||
|
||||
// generate sql with replacing operator string placeholders and replaced values.
|
||||
func (d *dbBase) GenerateOperatorSQL(mi *modelInfo, fi *fieldInfo, operator string, args []interface{}, tz *time.Location) (string, []interface{}) {
|
||||
sql := ""
|
||||
var sql string
|
||||
params := getFlatParams(fi, args, tz)
|
||||
|
||||
if len(params) == 0 {
|
||||
|
@ -103,8 +103,7 @@ func (d *dbBaseMysql) IndexExists(db dbQuerier, table string, name string) bool
|
||||
// If no will insert
|
||||
// Add "`" for mysql sql building
|
||||
func (d *dbBaseMysql) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, a *alias, args ...string) (int64, error) {
|
||||
|
||||
iouStr := ""
|
||||
var iouStr string
|
||||
argsMap := map[string]string{}
|
||||
|
||||
iouStr = "ON DUPLICATE KEY UPDATE"
|
||||
|
@ -420,7 +420,7 @@ func (o *orm) getRelQs(md interface{}, mi *modelInfo, fi *fieldInfo) *querySet {
|
||||
// table name can be string or struct.
|
||||
// e.g. QueryTable("user"), QueryTable(&user{}) or QueryTable((*User)(nil)),
|
||||
func (o *orm) QueryTable(ptrStructOrTableName interface{}) (qs QuerySeter) {
|
||||
name := ""
|
||||
var name string
|
||||
if table, ok := ptrStructOrTableName.(string); ok {
|
||||
name = snakeString(table)
|
||||
if mi, ok := modelCache.get(name); ok {
|
||||
|
@ -671,7 +671,7 @@ func (o *rawSet) queryRowsTo(container interface{}, keyCol, valueCol string) (in
|
||||
ind *reflect.Value
|
||||
)
|
||||
|
||||
typ := 0
|
||||
var typ int
|
||||
switch container.(type) {
|
||||
case *Params:
|
||||
typ = 1
|
||||
|
@ -1140,6 +1140,7 @@ func TestRelatedSel(t *testing.T) {
|
||||
}
|
||||
|
||||
err = qs.Filter("user_name", "nobody").RelatedSel("profile").One(&user)
|
||||
throwFail(t, err)
|
||||
throwFail(t, AssertIs(num, 1))
|
||||
throwFail(t, AssertIs(user.Profile, nil))
|
||||
|
||||
@ -1248,20 +1249,24 @@ func TestLoadRelated(t *testing.T) {
|
||||
|
||||
num, err = dORM.LoadRelated(&user, "Posts", true)
|
||||
throwFailNow(t, err)
|
||||
throwFailNow(t, AssertIs(num, 2))
|
||||
throwFailNow(t, AssertIs(len(user.Posts), 2))
|
||||
throwFailNow(t, AssertIs(user.Posts[0].User.UserName, "astaxie"))
|
||||
|
||||
num, err = dORM.LoadRelated(&user, "Posts", true, 1)
|
||||
throwFailNow(t, err)
|
||||
throwFailNow(t, AssertIs(num, 1))
|
||||
throwFailNow(t, AssertIs(len(user.Posts), 1))
|
||||
|
||||
num, err = dORM.LoadRelated(&user, "Posts", true, 0, 0, "-Id")
|
||||
throwFailNow(t, err)
|
||||
throwFailNow(t, AssertIs(num, 2))
|
||||
throwFailNow(t, AssertIs(len(user.Posts), 2))
|
||||
throwFailNow(t, AssertIs(user.Posts[0].Title, "Formatting"))
|
||||
|
||||
num, err = dORM.LoadRelated(&user, "Posts", true, 1, 1, "Id")
|
||||
throwFailNow(t, err)
|
||||
throwFailNow(t, AssertIs(num, 1))
|
||||
throwFailNow(t, AssertIs(len(user.Posts), 1))
|
||||
throwFailNow(t, AssertIs(user.Posts[0].Title, "Formatting"))
|
||||
|
||||
@ -1978,6 +1983,7 @@ func TestReadOrCreate(t *testing.T) {
|
||||
created, pk, err := dORM.ReadOrCreate(u, "UserName")
|
||||
throwFail(t, err)
|
||||
throwFail(t, AssertIs(created, true))
|
||||
throwFail(t, AssertIs(u.ID, pk))
|
||||
throwFail(t, AssertIs(u.UserName, "Kyle"))
|
||||
throwFail(t, AssertIs(u.Email, "kylemcc@gmail.com"))
|
||||
throwFail(t, AssertIs(u.Password, "other_pass"))
|
||||
@ -2134,6 +2140,7 @@ func TestUintPk(t *testing.T) {
|
||||
|
||||
created, pk, err := dORM.ReadOrCreate(u, "ID")
|
||||
throwFail(t, err)
|
||||
throwFail(t, AssertIs(pk, u.ID))
|
||||
throwFail(t, AssertIs(created, true))
|
||||
throwFail(t, AssertIs(u.Name, name))
|
||||
|
||||
|
@ -162,7 +162,9 @@ func (cp *Provider) SessionRead(sid string) (session.Store, error) {
|
||||
)
|
||||
|
||||
err = cp.b.Get(sid, &doc)
|
||||
if doc == nil {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if doc == nil {
|
||||
kv = make(map[interface{}]interface{})
|
||||
} else {
|
||||
kv, err = session.DecodeGob(doc)
|
||||
|
@ -74,8 +74,7 @@ func TestCookieEncodeDecode(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal("encodeCookie:", err)
|
||||
}
|
||||
dst := make(map[interface{}]interface{})
|
||||
dst, err = decodeCookie(block, hashKey, securityName, str, 3600)
|
||||
dst, err := decodeCookie(block, hashKey, securityName, str, 3600)
|
||||
if err != nil {
|
||||
t.Fatal("decodeCookie", err)
|
||||
}
|
||||
|
@ -307,8 +307,9 @@ func _getTemplate(t0 *template.Template, root string, subMods [][]string, others
|
||||
}
|
||||
//second check define
|
||||
for _, otherFile := range others {
|
||||
var data []byte
|
||||
fileAbsPath := filepath.Join(root, otherFile)
|
||||
data, err := ioutil.ReadFile(fileAbsPath)
|
||||
data, err = ioutil.ReadFile(fileAbsPath)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
@ -254,22 +254,22 @@ func TestParseFormTag(t *testing.T) {
|
||||
|
||||
objT := reflect.TypeOf(&user{}).Elem()
|
||||
|
||||
label, name, fType, id, class, ignored, required := parseFormTag(objT.Field(0))
|
||||
label, name, fType, _, _, ignored, _ := parseFormTag(objT.Field(0))
|
||||
if !(name == "name" && label == "年龄:" && fType == "text" && !ignored) {
|
||||
t.Errorf("Form Tag with name, label and type was not correctly parsed.")
|
||||
}
|
||||
|
||||
label, name, fType, id, class, ignored, required = parseFormTag(objT.Field(1))
|
||||
label, name, fType, _, _, ignored, _ = parseFormTag(objT.Field(1))
|
||||
if !(name == "NoName" && label == "年龄:" && fType == "hidden" && !ignored) {
|
||||
t.Errorf("Form Tag with label and type but without name was not correctly parsed.")
|
||||
}
|
||||
|
||||
label, name, fType, id, class, ignored, required = parseFormTag(objT.Field(2))
|
||||
label, name, fType, _, _, ignored, _ = parseFormTag(objT.Field(2))
|
||||
if !(name == "OnlyLabel" && label == "年龄:" && fType == "text" && !ignored) {
|
||||
t.Errorf("Form Tag containing only label was not correctly parsed.")
|
||||
}
|
||||
|
||||
label, name, fType, id, class, ignored, _ = parseFormTag(objT.Field(3))
|
||||
label, name, fType, id, class, ignored, _ := parseFormTag(objT.Field(3))
|
||||
if !(name == "name" && label == "OnlyName: " && fType == "text" && !ignored &&
|
||||
id == "name" && class == "form-name") {
|
||||
t.Errorf("Form Tag containing only name was not correctly parsed.")
|
||||
@ -280,7 +280,7 @@ func TestParseFormTag(t *testing.T) {
|
||||
t.Errorf("Form Tag that should be ignored was not correctly parsed.")
|
||||
}
|
||||
|
||||
_, name, _, _, _, _, required = parseFormTag(objT.Field(5))
|
||||
_, name, _, _, _, _, required := parseFormTag(objT.Field(5))
|
||||
if !(name == "name" && required) {
|
||||
t.Errorf("Form Tag containing only name and required was not correctly parsed.")
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func GrepFile(patten string, filename string) (lines []string, err error) {
|
||||
lines = make([]string, 0)
|
||||
reader := bufio.NewReader(fd)
|
||||
prefix := ""
|
||||
isLongLine := false
|
||||
var isLongLine bool
|
||||
for {
|
||||
byteLine, isPrefix, er := reader.ReadLine()
|
||||
if er != nil && er != io.EOF {
|
||||
|
@ -42,7 +42,7 @@ func TestGetValidFuncs(t *testing.T) {
|
||||
}
|
||||
|
||||
f, _ = tf.FieldByName("Tag")
|
||||
if vfs, err = getValidFuncs(f); err.Error() != "doesn't exsits Maxx valid function" {
|
||||
if _, err = getValidFuncs(f); err.Error() != "doesn't exsits Maxx valid function" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user