From 3e29078f68399a18e5a3d3bfac618b38eea8ee18 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 28 Apr 2017 21:38:08 +0800 Subject: [PATCH] add check ineffect and gofmt --- .travis.yml | 3 +++ httplib/httplib.go | 4 ++-- logs/alils/alils.go | 7 +++---- orm/orm_test.go | 4 +++- session/sess_file.go | 9 ++++++++- templatefunc_test.go | 10 +++++----- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index e3960c70..c5f11b9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,7 @@ install: - go get github.com/gogo/protobuf/proto - go get -u honnef.co/go/tools/cmd/gosimple - go get -u github.com/mdempsky/unconvert + - go get -u github.com/gordonklaus/ineffassign before_script: - psql --version - sh -c "if [ '$ORM_DRIVER' = 'postgres' ]; then psql -c 'create database orm_test;' -U postgres; fi" @@ -51,5 +52,7 @@ script: - go test -v ./... - gosimple -ignore "$(cat .gosimpleignore)" $(go list ./... | grep -v /vendor/) - unconvert $(go list ./... | grep -v /vendor/) + - ineffassign . + - find . ! \( -path './vendor' -prune \) -type f -name '*.go' -print0 | xargs -0 gofmt -l -s addons: postgresql: "9.4" diff --git a/httplib/httplib.go b/httplib/httplib.go index f232f31b..4fd572d6 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -520,9 +520,9 @@ func (b *BeegoHTTPRequest) Bytes() ([]byte, error) { return nil, err } b.body, err = ioutil.ReadAll(reader) - } else { - b.body, err = ioutil.ReadAll(resp.Body) + return b.body, err } + b.body, err = ioutil.ReadAll(resp.Body) return b.body, err } diff --git a/logs/alils/alils.go b/logs/alils/alils.go index 30a09243..aaee228a 100644 --- a/logs/alils/alils.go +++ b/logs/alils/alils.go @@ -2,11 +2,12 @@ package alils import ( "encoding/json" - "github.com/astaxie/beego/logs" - "github.com/gogo/protobuf/proto" "strings" "sync" "time" + + "github.com/astaxie/beego/logs" + "github.com/gogo/protobuf/proto" ) const ( @@ -124,12 +125,10 @@ func (c *aliLSWriter) WriteMsg(when time.Time, msg string, level int) (err error // 默认发到空Topic if lg == nil { - topic = "" content = msg lg = c.group[0] } } else { - topic = "" content = msg lg = c.group[0] } diff --git a/orm/orm_test.go b/orm/orm_test.go index a8b4fe69..128a86f3 100644 --- a/orm/orm_test.go +++ b/orm/orm_test.go @@ -135,7 +135,7 @@ func getCaller(skip int) string { if i := strings.LastIndex(funName, "."); i > -1 { funName = funName[i+1:] } - return fmt.Sprintf("%s:%d: \n%s", fn, line, strings.Join(codes, "\n")) + return fmt.Sprintf("%s:%s:%d: \n%s", fn, funName, line, strings.Join(codes, "\n")) } func throwFail(t *testing.T, err error, args ...interface{}) { @@ -1014,6 +1014,8 @@ func TestAll(t *testing.T) { var users3 []*User qs = dORM.QueryTable("user") num, err = qs.Filter("user_name", "nothing").All(&users3) + throwFailNow(t, err) + throwFailNow(t, AssertIs(num, 0)) throwFailNow(t, AssertIs(users3 == nil, false)) } diff --git a/session/sess_file.go b/session/sess_file.go index 12cf1f3f..3ca93d55 100644 --- a/session/sess_file.go +++ b/session/sess_file.go @@ -87,9 +87,16 @@ func (fs *FileSessionStore) SessionRelease(w http.ResponseWriter) { var f *os.File if err == nil { f, err = os.OpenFile(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid), os.O_RDWR, 0777) + if err != nil { + SLogger.Println(err) + return + } } else if os.IsNotExist(err) { f, err = os.Create(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid)) - + if err != nil { + SLogger.Println(err) + return + } } else { return } diff --git a/templatefunc_test.go b/templatefunc_test.go index 20d9b850..f40b5985 100644 --- a/templatefunc_test.go +++ b/templatefunc_test.go @@ -269,28 +269,28 @@ func TestParseFormTag(t *testing.T) { t.Errorf("Form Tag containing only label was not correctly parsed.") } - label, name, fType, id, class, ignored, required = 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.") } - label, name, fType, id, class, ignored, required = parseFormTag(objT.Field(4)) + _, _, _, _, _, ignored, _ = parseFormTag(objT.Field(4)) if !ignored { t.Errorf("Form Tag that should be ignored was not correctly parsed.") } - label, name, fType, id, class, ignored, 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.") } - label, name, fType, id, class, ignored, required = parseFormTag(objT.Field(6)) + _, name, _, _, _, _, required = parseFormTag(objT.Field(6)) if !(name == "name" && !required) { t.Errorf("Form Tag containing only name and ignore required was not correctly parsed.") } - label, name, fType, id, class, ignored, required = parseFormTag(objT.Field(7)) + _, name, _, _, _, _, required = parseFormTag(objT.Field(7)) if !(name == "name" && !required) { t.Errorf("Form Tag containing only name and not required was not correctly parsed.") }