From c76d4d1451d1417694e215c5aafc0fbe4a851ea6 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 24 Apr 2017 22:55:12 +0800 Subject: [PATCH 1/6] add publish target --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 7259aa6..d626070 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +VERSION = $(shell grep 'const version' cmd/commands/version/version.go | sed -E 's/.*"(.+)"$$/v\1/') + .PHONY: all test clean build install GOFLAGS ?= $(GOFLAGS:) @@ -18,3 +20,10 @@ bench: install clean: go clean $(GOFLAGS) -i ./... + +publish: + mkdir -p bin/$(VERSION) + cd bin/$(VERSION) + xgo -v -x --targets="windows/*,darwin/*,linux/386,linux/amd64,linux/arm-5,linux/arm64" -out bee_$(VERSION) github.com/beego/bee + cd .. + ghr -u beego -r bee $(VERSION) $(VERSION) \ No newline at end of file From 823dca76d5fe12aa915b0007667ccabdafa02272 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 28 Apr 2017 20:36:44 +0800 Subject: [PATCH 2/6] add gofmt check for travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 32a2f34..4cbff6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ install: - go get -u honnef.co/go/tools/cmd/unused - go get -u github.com/mdempsky/unconvert script: + - find . ! \( -path './vendor' -prune \) -type f -name '*.go' -print0 | xargs -0 gofmt -l -s - go vet $(go list ./... | grep -v /vendor/) - structcheck $(go list ./... | grep -v /vendor/) - gosimple -ignore "$(cat gosimple.ignore)" $(go list ./... | grep -v /vendor/) From e1f3353511ed4ded4c89ae7d738b1712552e170b Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 28 Apr 2017 22:53:38 +0800 Subject: [PATCH 3/6] add ineffassign check --- .travis.yml | 2 ++ cmd/commands/pack/pack.go | 2 +- generate/g_appcode.go | 6 ++---- generate/g_hproseappcode.go | 2 +- generate/swaggergen/g_docs.go | 7 ++----- logger/colors/colorwriter_windows.go | 2 +- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4cbff6e..b0e346b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ install: - go get -u honnef.co/go/tools/cmd/staticcheck - go get -u honnef.co/go/tools/cmd/unused - go get -u github.com/mdempsky/unconvert + - go get -u github.com/gordonklaus/ineffassign script: - find . ! \( -path './vendor' -prune \) -type f -name '*.go' -print0 | xargs -0 gofmt -l -s - go vet $(go list ./... | grep -v /vendor/) @@ -18,3 +19,4 @@ script: - staticcheck $(go list ./... | grep -v /vendor/) - unused $(go list ./... | grep -v /vendor/) - unconvert $(go list ./... | grep -v /vendor/) + - ineffassign . diff --git a/cmd/commands/pack/pack.go b/cmd/commands/pack/pack.go index ee7eced..becddcc 100644 --- a/cmd/commands/pack/pack.go +++ b/cmd/commands/pack/pack.go @@ -417,7 +417,7 @@ func packDirectory(output io.Writer, excludePrefix []string, excludeSuffix []str func packApp(cmd *commands.Command, args []string) int { output := cmd.Out() curPath, _ := os.Getwd() - thePath := "" + var thePath string nArgs := []string{} has := false diff --git a/generate/g_appcode.go b/generate/g_appcode.go index fd6a3ed..f575568 100644 --- a/generate/g_appcode.go +++ b/generate/g_appcode.go @@ -503,9 +503,7 @@ func (mysqlDB *MysqlDB) GetColumns(db *sql.DB, table *Table, blackList map[strin // GetGoDataType maps an SQL data type to Golang data type func (*MysqlDB) GetGoDataType(sqlType string) (string, error) { - var typeMapping = map[string]string{} - typeMapping = typeMappingMysql - if v, ok := typeMapping[sqlType]; ok { + if v, ok := typeMappingMysql[sqlType]; ok { return v, nil } return "", fmt.Errorf("data type '%s' not found", sqlType) @@ -766,7 +764,7 @@ func writeModelFiles(tables []*Table, mPath string, selectedTables map[string]bo continue } } - template := "" + var template string if tb.Pk == "" { template = StructModelTPL } else { diff --git a/generate/g_hproseappcode.go b/generate/g_hproseappcode.go index f73d6ff..f6d352d 100644 --- a/generate/g_hproseappcode.go +++ b/generate/g_hproseappcode.go @@ -369,7 +369,7 @@ func writeHproseModelFiles(tables []*Table, mPath string, selectedTables map[str continue } } - template := "" + var template string if tb.Pk == "" { template = HproseStructModelTPL } else { diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index a9f1c0a..36dcec4 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -216,7 +216,7 @@ func GenerateDocs(curpath string) { for _, p := range params { switch pp := p.(type) { case *ast.CallExpr: - controllerName := "" + var controllerName string if selname := pp.Fun.(*ast.SelectorExpr).Sel.String(); selname == "NSNamespace" { s, params := analyseNewNamespace(pp) for _, sp := range params { @@ -298,12 +298,10 @@ func analyseNSInclude(baseurl string, ce *ast.CallExpr) string { } if apis, ok := controllerList[cname]; ok { for rt, item := range apis { - tag := "" + tag := cname if baseurl != "" { rt = baseurl + rt tag = strings.Trim(baseurl, "/") - } else { - tag = cname } if item.Get != nil { item.Get.Tags = []string{tag} @@ -749,7 +747,6 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string if st.Fields.List != nil { m.Properties = make(map[string]swagger.Propertie) for _, field := range st.Fields.List { - realType := "" isSlice, realType, sType := typeAnalyser(field) if (isSlice && isBasicType(realType)) || sType == "object" { if len(strings.Split(realType, " ")) > 1 { diff --git a/logger/colors/colorwriter_windows.go b/logger/colors/colorwriter_windows.go index d4c567a..67acb93 100644 --- a/logger/colors/colorwriter_windows.go +++ b/logger/colors/colorwriter_windows.go @@ -360,7 +360,7 @@ func isParameterChar(b byte) bool { } func (cw *colorWriter) 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() From 3f63cd706f1c4ba58116bcc6ce159dc6c92b5037 Mon Sep 17 00:00:00 2001 From: guoshaowei Date: Fri, 5 May 2017 10:59:45 +0800 Subject: [PATCH 4/6] fix gen doc slice type bug --- generate/swaggergen/g_docs.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 36dcec4..268a249 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -762,7 +762,7 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string mp := swagger.Propertie{} if isSlice { mp.Type = "array" - if isBasicType(realType) { + if isBasicType(strings.Replace(realType, "[]", "", -1)) { typeFormat := strings.Split(sType, ":") mp.Items = &swagger.Propertie{ Type: typeFormat[0], @@ -864,6 +864,11 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) { if arr, ok := f.Type.(*ast.ArrayType); ok { + //arr.Len nil for slice types + if arr.Len == nil { + return true, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)] + } + if isBasicType(fmt.Sprint(arr.Elt)) { return false, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)] } From 50ae47c61f2195cfb0c2d4cd9fe8f3bbc6358b9b Mon Sep 17 00:00:00 2001 From: guoshaowei Date: Fri, 5 May 2017 11:31:03 +0800 Subject: [PATCH 5/6] fix gen doc slice type bug --- generate/swaggergen/g_docs.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 268a249..635ef06 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -864,13 +864,8 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) { if arr, ok := f.Type.(*ast.ArrayType); ok { - //arr.Len nil for slice types - if arr.Len == nil { - return true, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)] - } - if isBasicType(fmt.Sprint(arr.Elt)) { - return false, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)] + return true, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)] } if mp, ok := arr.Elt.(*ast.MapType); ok { return false, fmt.Sprintf("map[%v][%v]", mp.Key, mp.Value), "object" From d34d2da58267da142f960cc6af1d8f089eb8bbc9 Mon Sep 17 00:00:00 2001 From: wzshiming Date: Sat, 6 May 2017 18:15:23 +0800 Subject: [PATCH 6/6] Generate document errors in windows --- utils/utils.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index 13e50b1..ed1905f 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -61,7 +61,8 @@ func GetGOPATHs() []string { // IsInGOPATH checks whether the path is inside of any GOPATH or not func IsInGOPATH(thePath string) bool { for _, gopath := range GetGOPATHs() { - if strings.Contains(thePath, filepath.Join(gopath, "src")) { + b, _ := filepath.Rel(thePath, filepath.Join(gopath, "src")) + if strings.Contains(b, "..") { return true } }