From e79c42add1ef42484d507a58959debcdb65fa0d4 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 19 Aug 2020 16:10:43 +0800 Subject: [PATCH] add go report badge --- core/stores/kv/store_test.go | 2 +- readme.md | 1 + tools/goctl/api/parser/rootstate.go | 2 -- tools/goctl/model/sql/parser/parser.go | 14 ++++++++------ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/stores/kv/store_test.go b/core/stores/kv/store_test.go index a3b3b27d..a6385dab 100644 --- a/core/stores/kv/store_test.go +++ b/core/stores/kv/store_test.go @@ -381,7 +381,7 @@ func TestRedis_SortedSet(t *testing.T) { rank, err := client.Zrank("key", "value2") assert.Nil(t, err) assert.Equal(t, int64(1), rank) - rank, err = client.Zrank("key", "value4") + _, err = client.Zrank("key", "value4") assert.Equal(t, redis.Nil, err) num, err := client.Zrem("key", "value2", "value3") assert.Nil(t, err) diff --git a/readme.md b/readme.md index a34cf004..e8272c3e 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,7 @@ [![Go](https://github.com/tal-tech/go-zero/workflows/Go/badge.svg?branch=master)](https://github.com/tal-tech/go-zero/actions) [![codecov](https://codecov.io/gh/tal-tech/go-zero/branch/master/graph/badge.svg)](https://codecov.io/gh/tal-tech/go-zero) +[![Go Report Card](https://goreportcard.com/badge/github.com/tal-tech/go-zero)](https://goreportcard.com/report/github.com/tal-tech/go-zero) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ## 1. go-zero框架背景 diff --git a/tools/goctl/api/parser/rootstate.go b/tools/goctl/api/parser/rootstate.go index 297eabf7..994f70bd 100644 --- a/tools/goctl/api/parser/rootstate.go +++ b/tools/goctl/api/parser/rootstate.go @@ -99,8 +99,6 @@ func (s rootState) processToken(token string, annos []spec.Annotation) (state, e switch token { case infoDirective: return newInfoState(s.baseState), nil - //case typeDirective: - //return newTypeState(s.baseState, annos), nil case serviceDirective: return newServiceState(s.baseState, annos), nil default: diff --git a/tools/goctl/model/sql/parser/parser.go b/tools/goctl/model/sql/parser/parser.go index b3701ae3..0b638545 100644 --- a/tools/goctl/model/sql/parser/parser.go +++ b/tools/goctl/model/sql/parser/parser.go @@ -42,14 +42,17 @@ func Parse(ddl string) (*Table, error) { if err != nil { return nil, err } + ddlStmt, ok := stmt.(*sqlparser.DDL) if !ok { return nil, unSupportDDL } + action := ddlStmt.Action if action != sqlparser.CreateStr { return nil, fmt.Errorf("expected [CREATE] action,but found: %s", action) } + tableName := ddlStmt.NewName.Name.String() tableSpec := ddlStmt.TableSpec if tableSpec == nil { @@ -58,7 +61,6 @@ func Parse(ddl string) (*Table, error) { columns := tableSpec.Columns indexes := tableSpec.Indexes - keyMap := make(map[string]KeyType) for _, index := range indexes { info := index.Info @@ -69,6 +71,7 @@ func Parse(ddl string) (*Table, error) { if len(index.Columns) > 1 { return nil, errPrimaryKey } + keyMap[index.Columns[0].Column.String()] = primary continue } @@ -91,11 +94,9 @@ func Parse(ddl string) (*Table, error) { keyMap[columnName] = normal } } - var ( - fields []Field - primaryKey Primary - ) + var fields []Field + var primaryKey Primary for _, column := range columns { if column == nil { continue @@ -108,6 +109,7 @@ func Parse(ddl string) (*Table, error) { if err != nil { return nil, err } + var field Field field.Name = stringx.From(column.Name.String()) field.DataBaseType = column.Type.Type @@ -126,10 +128,10 @@ func Parse(ddl string) (*Table, error) { } fields = append(fields, field) } + return &Table{ Name: stringx.From(tableName), PrimaryKey: primaryKey, Fields: fields, }, nil - }