lunny/fix_fmt_lint (#53)

This commit is contained in:
Lunny Xiao 2019-07-15 13:42:17 +00:00 committed by Gitea
parent 817c743b93
commit 5d3ffb50de
12 changed files with 48 additions and 36 deletions

View File

@ -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 ]

View File

@ -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

2
db.go
View File

@ -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) {

View File

@ -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()

View File

@ -7,6 +7,8 @@ package core
import "errors"
var (
// 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")
)

View File

@ -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{})

View File

@ -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)}
}

View File

@ -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

View File

@ -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()
}

View File

@ -11,6 +11,7 @@ import (
"reflect"
)
// Stmt reprents a stmt objects
type Stmt struct {
*sql.Stmt
db *DB

View File

@ -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
}