1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 13:40:55 +00:00

add check ineffect and gofmt

This commit is contained in:
astaxie 2017-04-28 21:38:08 +08:00
parent f311ae9ebe
commit 3e29078f68
6 changed files with 24 additions and 13 deletions

View File

@ -35,6 +35,7 @@ install:
- go get github.com/gogo/protobuf/proto - go get github.com/gogo/protobuf/proto
- go get -u honnef.co/go/tools/cmd/gosimple - go get -u honnef.co/go/tools/cmd/gosimple
- go get -u github.com/mdempsky/unconvert - go get -u github.com/mdempsky/unconvert
- go get -u github.com/gordonklaus/ineffassign
before_script: before_script:
- psql --version - psql --version
- sh -c "if [ '$ORM_DRIVER' = 'postgres' ]; then psql -c 'create database orm_test;' -U postgres; fi" - sh -c "if [ '$ORM_DRIVER' = 'postgres' ]; then psql -c 'create database orm_test;' -U postgres; fi"
@ -51,5 +52,7 @@ script:
- go test -v ./... - go test -v ./...
- gosimple -ignore "$(cat .gosimpleignore)" $(go list ./... | grep -v /vendor/) - gosimple -ignore "$(cat .gosimpleignore)" $(go list ./... | grep -v /vendor/)
- unconvert $(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: addons:
postgresql: "9.4" postgresql: "9.4"

View File

@ -520,9 +520,9 @@ func (b *BeegoHTTPRequest) Bytes() ([]byte, error) {
return nil, err return nil, err
} }
b.body, err = ioutil.ReadAll(reader) b.body, err = ioutil.ReadAll(reader)
} else { return b.body, err
b.body, err = ioutil.ReadAll(resp.Body)
} }
b.body, err = ioutil.ReadAll(resp.Body)
return b.body, err return b.body, err
} }

View File

@ -2,11 +2,12 @@ package alils
import ( import (
"encoding/json" "encoding/json"
"github.com/astaxie/beego/logs"
"github.com/gogo/protobuf/proto"
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/astaxie/beego/logs"
"github.com/gogo/protobuf/proto"
) )
const ( const (
@ -124,12 +125,10 @@ func (c *aliLSWriter) WriteMsg(when time.Time, msg string, level int) (err error
// 默认发到空Topic // 默认发到空Topic
if lg == nil { if lg == nil {
topic = ""
content = msg content = msg
lg = c.group[0] lg = c.group[0]
} }
} else { } else {
topic = ""
content = msg content = msg
lg = c.group[0] lg = c.group[0]
} }

View File

@ -135,7 +135,7 @@ func getCaller(skip int) string {
if i := strings.LastIndex(funName, "."); i > -1 { if i := strings.LastIndex(funName, "."); i > -1 {
funName = 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{}) { func throwFail(t *testing.T, err error, args ...interface{}) {
@ -1014,6 +1014,8 @@ func TestAll(t *testing.T) {
var users3 []*User var users3 []*User
qs = dORM.QueryTable("user") qs = dORM.QueryTable("user")
num, err = qs.Filter("user_name", "nothing").All(&users3) num, err = qs.Filter("user_name", "nothing").All(&users3)
throwFailNow(t, err)
throwFailNow(t, AssertIs(num, 0))
throwFailNow(t, AssertIs(users3 == nil, false)) throwFailNow(t, AssertIs(users3 == nil, false))
} }

View File

@ -87,9 +87,16 @@ func (fs *FileSessionStore) SessionRelease(w http.ResponseWriter) {
var f *os.File var f *os.File
if err == nil { 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) 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) { } else if os.IsNotExist(err) {
f, err = os.Create(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid)) 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 { } else {
return return
} }

View File

@ -269,28 +269,28 @@ func TestParseFormTag(t *testing.T) {
t.Errorf("Form Tag containing only label was not correctly parsed.") 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 && if !(name == "name" && label == "OnlyName: " && fType == "text" && !ignored &&
id == "name" && class == "form-name") { id == "name" && class == "form-name") {
t.Errorf("Form Tag containing only name was not correctly parsed.") 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 { if !ignored {
t.Errorf("Form Tag that should be ignored was not correctly parsed.") 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) { if !(name == "name" && required) {
t.Errorf("Form Tag containing only name and required was not correctly parsed.") 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) { if !(name == "name" && !required) {
t.Errorf("Form Tag containing only name and ignore required was not correctly parsed.") 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) { if !(name == "name" && !required) {
t.Errorf("Form Tag containing only name and not required was not correctly parsed.") t.Errorf("Form Tag containing only name and not required was not correctly parsed.")
} }