From 5d3ffb50debff768df1d50d08fc99474fca1cf46 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 15 Jul 2019 13:42:17 +0000 Subject: [PATCH] lunny/fix_fmt_lint (#53) --- .drone.yml | 1 + README.md | 2 ++ db.go | 2 ++ dialect.go | 2 +- error.go | 4 +++- ilogger.go | 4 +++- index.go | 7 ++++--- mapper.go | 8 ++++---- rows.go | 2 +- stmt.go | 1 + table.go | 9 +++++---- type.go | 42 +++++++++++++++++++++--------------------- 12 files changed, 48 insertions(+), 36 deletions(-) diff --git a/.drone.yml b/.drone.yml index 41390c8d..1ef2b813 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,6 +26,7 @@ pipeline: - go get -u github.com/go-xorm/sqlfiddle - go get -u github.com/go-sql-driver/mysql - go get -u github.com/mattn/go-sqlite3 + - go vet - go test -v -race -coverprofile=coverage.txt -covermode=atomic -dbConn="root:@tcp(mysql:3306)/core_test?charset=utf8mb4" when: event: [ push, tag, pull_request ] diff --git a/README.md b/README.md index 2277163a..c2cedcae 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ Core is a lightweight wrapper of sql.DB. [![Build Status](https://drone.gitea.com/api/badges/xorm/core/status.svg)](https://drone.gitea.com/xorm/core) +[![](http://gocover.io/_badge/xorm.io/core)](http://gocover.io/xorm.io/core) +[![Go Report Card](https://goreportcard.com/badge/code.gitea.io/gitea)](https://goreportcard.com/report/xorm.io/core) # Open ```Go diff --git a/db.go b/db.go index 5a7d59a0..4847937c 100644 --- a/db.go +++ b/db.go @@ -15,6 +15,7 @@ import ( ) var ( + // DefaultCacheSize sets the default cache size DefaultCacheSize = 200 ) @@ -198,6 +199,7 @@ var ( re = regexp.MustCompile(`[?](\w+)`) ) +// ExecMapContext exec map with context.Context // insert into (name) values (?) // insert into (name) values (?name) func (db *DB) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error) { diff --git a/dialect.go b/dialect.go index 6c88e6c3..9d214f31 100644 --- a/dialect.go +++ b/dialect.go @@ -311,7 +311,7 @@ func RegisterDialect(dbName DbType, dialectFunc func() Dialect) { dialects[strings.ToLower(string(dbName))] = dialectFunc // !nashtsai! allow override dialect } -// QueryDialect query if registed database dialect +// QueryDialect query if registered database dialect func QueryDialect(dbName DbType) Dialect { if d, ok := dialects[strings.ToLower(string(dbName))]; ok { return d() diff --git a/error.go b/error.go index 63ea53e4..1fd18348 100644 --- a/error.go +++ b/error.go @@ -7,6 +7,8 @@ package core import "errors" var ( - ErrNoMapPointer = errors.New("mp should be a map's pointer") + // ErrNoMapPointer represents error when no map pointer + ErrNoMapPointer = errors.New("mp should be a map's pointer") + // ErrNoStructPointer represents error when no struct pointer ErrNoStructPointer = errors.New("mp should be a struct's pointer") ) diff --git a/ilogger.go b/ilogger.go index 348ab88f..0c17750c 100644 --- a/ilogger.go +++ b/ilogger.go @@ -4,8 +4,10 @@ package core +// LogLevel defines a log level type LogLevel int +// enumerate all LogLevels const ( // !nashtsai! following level also match syslog.Priority value LOG_DEBUG LogLevel = iota @@ -16,7 +18,7 @@ const ( LOG_UNKNOWN ) -// logger interface +// ILogger is a logger interface type ILogger interface { Debug(v ...interface{}) Debugf(format string, v ...interface{}) diff --git a/index.go b/index.go index ac97b685..2915428f 100644 --- a/index.go +++ b/index.go @@ -9,12 +9,13 @@ import ( "strings" ) +// enumerate all index types const ( IndexType = iota + 1 UniqueType ) -// database index +// Index represents a database index type Index struct { IsRegular bool Name string @@ -35,7 +36,7 @@ func (index *Index) XName(tableName string) string { return index.Name } -// add columns which will be composite index +// AddColumn add columns which will be composite index func (index *Index) AddColumn(cols ...string) { for _, col := range cols { index.Cols = append(index.Cols, col) @@ -65,7 +66,7 @@ func (index *Index) Equal(dst *Index) bool { return true } -// new an index +// NewIndex new an index object func NewIndex(name string, indexType int) *Index { return &Index{true, name, indexType, make([]string, 0)} } diff --git a/mapper.go b/mapper.go index ec44ea0d..4df05cb8 100644 --- a/mapper.go +++ b/mapper.go @@ -9,7 +9,7 @@ import ( "sync" ) -// name translation between struct, fields names and table, column names +// IMapper represents a name convertation between struct's fields name and table's column name type IMapper interface { Obj2Table(string) string Table2Obj(string) string @@ -184,7 +184,7 @@ func (mapper GonicMapper) Table2Obj(name string) string { return string(newstr) } -// A GonicMapper that contains a list of common initialisms taken from golang/lint +// LintGonicMapper is A GonicMapper that contains a list of common initialisms taken from golang/lint var LintGonicMapper = GonicMapper{ "API": true, "ASCII": true, @@ -221,7 +221,7 @@ var LintGonicMapper = GonicMapper{ "XSS": true, } -// provide prefix table name support +// PrefixMapper provides prefix table name support type PrefixMapper struct { Mapper IMapper Prefix string @@ -239,7 +239,7 @@ func NewPrefixMapper(mapper IMapper, prefix string) PrefixMapper { return PrefixMapper{mapper, prefix} } -// provide suffix table name support +// SuffixMapper provides suffix table name support type SuffixMapper struct { Mapper IMapper Suffix string diff --git a/rows.go b/rows.go index 2b046d84..a1e8bfbc 100644 --- a/rows.go +++ b/rows.go @@ -170,7 +170,7 @@ func (rs *Rows) ScanMap(dest interface{}) error { newDest := make([]interface{}, len(cols)) vvv := vv.Elem() - for i, _ := range cols { + for i := range cols { newDest[i] = rs.db.reflectNew(vvv.Type().Elem()).Interface() } diff --git a/stmt.go b/stmt.go index 20ee202b..8a21541a 100644 --- a/stmt.go +++ b/stmt.go @@ -11,6 +11,7 @@ import ( "reflect" ) +// Stmt reprents a stmt objects type Stmt struct { *sql.Stmt db *DB diff --git a/table.go b/table.go index d129e60f..0a3889e1 100644 --- a/table.go +++ b/table.go @@ -9,7 +9,7 @@ import ( "strings" ) -// database table +// Table represents a database table type Table struct { Name string Type reflect.Type @@ -41,6 +41,7 @@ func NewEmptyTable() *Table { return NewTable("", nil) } +// NewTable creates a new Table object func NewTable(name string, t reflect.Type) *Table { return &Table{Name: name, Type: t, columnsSeq: make([]string, 0), @@ -87,7 +88,7 @@ func (table *Table) GetColumnIdx(name string, idx int) *Column { return nil } -// if has primary key, return column +// PKColumns reprents all primary key columns func (table *Table) PKColumns() []*Column { columns := make([]*Column, len(table.PrimaryKeys)) for i, name := range table.PrimaryKeys { @@ -117,7 +118,7 @@ func (table *Table) DeletedColumn() *Column { return table.GetColumn(table.Deleted) } -// add a column to table +// AddColumn adds a column to table func (table *Table) AddColumn(col *Column) { table.columnsSeq = append(table.columnsSeq, col.Name) table.columns = append(table.columns, col) @@ -148,7 +149,7 @@ func (table *Table) AddColumn(col *Column) { } } -// add an index or an unique to table +// AddIndex adds an index or an unique to table func (table *Table) AddIndex(index *Index) { table.Indexes[index.Name] = index } diff --git a/type.go b/type.go index 81649536..14d6e12e 100644 --- a/type.go +++ b/type.go @@ -87,16 +87,16 @@ var ( UniqueIdentifier = "UNIQUEIDENTIFIER" SysName = "SYSNAME" - Date = "DATE" - DateTime = "DATETIME" - SmallDateTime = "SMALLDATETIME" - Time = "TIME" - TimeStamp = "TIMESTAMP" - TimeStampz = "TIMESTAMPZ" + Date = "DATE" + DateTime = "DATETIME" + SmallDateTime = "SMALLDATETIME" + Time = "TIME" + TimeStamp = "TIMESTAMP" + TimeStampz = "TIMESTAMPZ" - Decimal = "DECIMAL" - Numeric = "NUMERIC" - Money = "MONEY" + Decimal = "DECIMAL" + Numeric = "NUMERIC" + Money = "MONEY" SmallMoney = "SMALLMONEY" Real = "REAL" @@ -147,19 +147,19 @@ var ( Clob: TEXT_TYPE, SysName: TEXT_TYPE, - Date: TIME_TYPE, - DateTime: TIME_TYPE, - Time: TIME_TYPE, - TimeStamp: TIME_TYPE, - TimeStampz: TIME_TYPE, - SmallDateTime: TIME_TYPE, + Date: TIME_TYPE, + DateTime: TIME_TYPE, + Time: TIME_TYPE, + TimeStamp: TIME_TYPE, + TimeStampz: TIME_TYPE, + SmallDateTime: TIME_TYPE, - Decimal: NUMERIC_TYPE, - Numeric: NUMERIC_TYPE, - Real: NUMERIC_TYPE, - Float: NUMERIC_TYPE, - Double: NUMERIC_TYPE, - Money: NUMERIC_TYPE, + Decimal: NUMERIC_TYPE, + Numeric: NUMERIC_TYPE, + Real: NUMERIC_TYPE, + Float: NUMERIC_TYPE, + Double: NUMERIC_TYPE, + Money: NUMERIC_TYPE, SmallMoney: NUMERIC_TYPE, Binary: BLOB_TYPE,